Skip to content

Commit 6db9ba9

Browse files
author
carabasdaniel
authored
Merge pull request #1066 from pegasd/stricter_type_aliases
Make type aliases stricter
2 parents 91e7104 + 6d82827 commit 6db9ba9

25 files changed

+103
-27
lines changed

REFERENCE.md

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -6722,13 +6722,13 @@ Alias of `Variant[Stdlib::Windowspath, Stdlib::Unixpath]`
67226722

67236723
Type to match base32 String
67246724

6725-
Alias of `Pattern[/^[a-z2-7]+={,6}$/, /^[A-Z2-7]+={,6}$/]`
6725+
Alias of `Pattern[/\A[a-z2-7]+={,6}\z/, /\A[A-Z2-7]+={,6}\z/]`
67266726

67276727
### Stdlib::Base64
67286728

67296729
Type to match base64 String
67306730

6731-
Alias of `Pattern[/^[a-zA-Z0-9\/\+]+={,2}$/]`
6731+
Alias of `Pattern[/\A[a-zA-Z0-9\/\+]+={,2}\z/]`
67326732

67336733
### Stdlib::Compat::Absolute_path
67346734

@@ -6870,34 +6870,34 @@ Alias of `Enum['stopped', 'running']`
68706870

68716871
See `man chmod.1` for the regular expression for symbolic mode
68726872

6873-
Alias of `Pattern[/^(([0-7]{1,4})|(([ugoa]*([-+=]([rwxXst]*|[ugo]))+|[-+=][0-7]+)(,([ugoa]*([-+=]([rwxXst]*|[ugo]))+|[-+=][0-7]+))*))$/]`
6873+
Alias of `Pattern[/\A(([0-7]{1,4})|(([ugoa]*([-+=]([rwxXst]*|[ugo]))+|[-+=][0-7]+)(,([ugoa]*([-+=]([rwxXst]*|[ugo]))+|[-+=][0-7]+))*))\z/]`
68746874

68756875
### Stdlib::Filesource
68766876

68776877
Validate the source parameter on file types
68786878

68796879
Alias of `Variant[Stdlib::Absolutepath, Stdlib::HTTPUrl, Pattern[
6880-
/^file:\/\/\/([^\/\0]+(\/)?)+$/,
6881-
/^puppet:\/\/(([\w-]+\.?)+)?\/([^\/\0]+(\/)?)+$/,
6880+
/\Afile:\/\/\/([^\n\/\0]+(\/)?)+\z/,
6881+
/\Apuppet:\/\/(([\w-]+\.?)+)?\/([^\n\/\0]+(\/)?)+\z/,
68826882
]]`
68836883

68846884
### Stdlib::Fqdn
68856885

68866886
The Stdlib::Fqdn data type.
68876887

6888-
Alias of `Pattern[/^(([a-zA-Z0-9]|[a-zA-Z0-9][a-zA-Z0-9\-]*[a-zA-Z0-9])\.)*([A-Za-z0-9]|[A-Za-z0-9][A-Za-z0-9\-]*[A-Za-z0-9])$/]`
6888+
Alias of `Pattern[/\A(([a-zA-Z0-9]|[a-zA-Z0-9][a-zA-Z0-9\-]*[a-zA-Z0-9])\.)*([A-Za-z0-9]|[A-Za-z0-9][A-Za-z0-9\-]*[A-Za-z0-9])\z/]`
68896889

68906890
### Stdlib::HTTPSUrl
68916891

68926892
The Stdlib::HTTPSUrl data type.
68936893

6894-
Alias of `Pattern[/(?i:^https:\/\/)/]`
6894+
Alias of `Pattern[/(?i:\Ahttps:\/\/.*\z)/]`
68956895

68966896
### Stdlib::HTTPUrl
68976897

68986898
The Stdlib::HTTPUrl data type.
68996899

6900-
Alias of `Pattern[/(?i:^https?:\/\/)/]`
6900+
Alias of `Pattern[/(?i:\Ahttps?:\/\/.*\z)/]`
69016901

69026902
### Stdlib::Host
69036903

@@ -6993,7 +6993,7 @@ Alias of `Pattern[/\A[[:xdigit:]]{1,4}(:[[:xdigit:]]{1,4}){7}\z/]`
69936993

69946994
A type for a MAC address
69956995

6996-
Alias of `Pattern[/^([0-9A-Fa-f]{2}[:-]){5}([0-9A-Fa-f]{2})$/, /^([0-9A-Fa-f]{2}[:-]){19}([0-9A-Fa-f]{2})$/]`
6996+
Alias of `Pattern[/\A([0-9A-Fa-f]{2}[:-]){5}([0-9A-Fa-f]{2})\z/, /\A([0-9A-Fa-f]{2}[:-]){19}([0-9A-Fa-f]{2})\z/]`
69976997

69986998
### Stdlib::ObjectStore
69996999

@@ -7005,13 +7005,13 @@ Alias of `Variant[Stdlib::ObjectStore::GSUri, Stdlib::ObjectStore::S3Uri]`
70057005

70067006
The Stdlib::ObjectStore::GSUri data type.
70077007

7008-
Alias of `Pattern[/^gs:\/\//]`
7008+
Alias of `Pattern[/\Ags:\/\/.*\z/]`
70097009

70107010
### Stdlib::ObjectStore::S3Uri
70117011

70127012
The Stdlib::ObjectStore::S3Uri data type.
70137013

7014-
Alias of `Pattern[/^s3:\/\//]`
7014+
Alias of `Pattern[/\As3:\/\/.*\z/]`
70157015

70167016
### Stdlib::Port
70177017

@@ -7041,13 +7041,13 @@ Alias of `Enum['kern', 'user', 'mail', 'daemon', 'auth', 'syslog', 'lpr', 'news'
70417041

70427042
this regex rejects any path component that does not start with "/" or is NUL
70437043

7044-
Alias of `Pattern[/^\/([^\/\0]+\/*)*$/]`
7044+
Alias of `Pattern[/\A\/([^\n\/\0]+\/*)*\z/]`
70457045

70467046
### Stdlib::Windowspath
70477047

70487048
The Stdlib::Windowspath data type.
70497049

7050-
Alias of `Pattern[/^(([a-zA-Z]:[\\\/])|([\\\/][\\\/][^\\\/]+[\\\/][^\\\/]+)|([\\\/][\\\/]\?[\\\/][^\\\/]+))/]`
7050+
Alias of `Pattern[/\A(([a-zA-Z]:[\\\/])|([\\\/][\\\/][^\\\/]+[\\\/][^\\\/]+)|([\\\/][\\\/]\?[\\\/][^\\\/]+)).*\z/]`
70517051

70527052
### Stdlib::Yes_no
70537053

spec/type_aliases/base32_spec.rb

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,9 @@
1818
[nil, nil],
1919
{ 'foo' => 'bar' },
2020
{},
21+
"\nASDASDDASD3453453",
22+
"\nASDASDDASD3453453\n",
23+
"ASDASDDASD3453453\n",
2124
'',
2225
'asdasd!@#$',
2326
'=asdasd9879876876+/',

spec/type_aliases/base64_spec.rb

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,9 @@
1818
{ 'foo' => 'bar' },
1919
{},
2020
'',
21+
"\nasdasdASDSADA342386832/746+=",
22+
"\nasdasdASDSADA342386832/746+=\n",
23+
"asdasdASDSADA342386832/746+=\n",
2124
'asdasd!@#$',
2225
'=asdasd9879876876+/',
2326
'asda=sd9879876876+/',

spec/type_aliases/filemode_spec.rb

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,9 @@
4141
{ 'foo' => 'bar' },
4242
{},
4343
'',
44+
"\n0644",
45+
"\n0644\n",
46+
"0644\n",
4447
'ネット',
4548
'55555',
4649
'0x123',

spec/type_aliases/filesource_spec.rb

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,12 @@
4242
{ 'foo' => 'bar' },
4343
{},
4444
'',
45+
"\nfile:///foo/bar.log",
46+
"\nfile:///foo/bar.log\n",
47+
"file:///foo/bar.log\n",
48+
"\npuppet:///modules/foo/bar.log",
49+
"\npuppet:///modules/foo/bar.log\n",
50+
"puppet:///modules/foo/bar.log\n",
4551
'*/Users//nope',
4652
'\\Users/hc/wksp/stdlib',
4753
'C:noslashes',

spec/type_aliases/fqdn_spec.rb

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,9 @@
1818
{ 'foo' => 'bar' },
1919
{},
2020
'',
21+
"\nexample",
22+
"\nexample\n",
23+
"example\n",
2124
'2001:DB8::1',
2225
'www www.example.com',
2326
].each do |value|

spec/type_aliases/httpsurl_spec.rb

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,9 @@
1919
{ 'foo' => 'bar' },
2020
{},
2121
'',
22+
"\nhttps://hello.com",
23+
"\nhttps://hello.com\n",
24+
"https://hello.com\n",
2225
'httds://notquiteright.org',
2326
'hptts:/nah',
2427
'https;//notrightbutclose.org',

spec/type_aliases/httpurl_spec.rb

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,9 @@
2020
{ 'foo' => 'bar' },
2121
{},
2222
'',
23+
"\nhttp://hello.com",
24+
"\nhttp://hello.com\n",
25+
"http://hello.com\n",
2326
'httds://notquiteright.org',
2427
'hptts:/nah',
2528
'https;//notrightbutclose.org',

spec/type_aliases/mac_spec.rb

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
require 'spec_helper'
2+
3+
if Puppet::Util::Package.versioncmp(Puppet.version, '4.5.0') >= 0
4+
describe 'Stdlib::MAC' do
5+
describe 'valid handling' do
6+
[
7+
'00:a0:1f:12:7f:a0',
8+
'00:A0:1F:12:7F:A0',
9+
'00-A0-1F-12-7F-A0',
10+
'80:00:02:09:fe:80:00:00:00:00:00:00:00:24:65:ff:ff:91:a3:12',
11+
].each do |value|
12+
describe value.inspect do
13+
it { is_expected.to allow_value(value) }
14+
end
15+
end
16+
end
17+
18+
describe 'invalid path handling' do
19+
context 'with garbage inputs' do
20+
[
21+
nil,
22+
[nil],
23+
[nil, nil],
24+
{ 'foo' => 'bar' },
25+
{},
26+
'',
27+
'one',
28+
'00:00:00:00:00:0g',
29+
"\n00:a0:1f:12:7f:a0",
30+
"\n00:a0:1f:12:7f:a0\n",
31+
"00:a0:1f:12:7f:a0\n",
32+
].each do |value|
33+
describe value.inspect do
34+
it { is_expected.not_to allow_value(value) }
35+
end
36+
end
37+
end
38+
end
39+
end
40+
end

spec/type_aliases/objectstore_gsuri_spec.rb

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,9 @@
1616
describe 'rejects other values' do
1717
[
1818
'',
19+
"\ngs://mybucket/myfile.csv",
20+
"\ngs://mybucket/myfile.csv\n",
21+
"gs://mybucket/myfile.csv\n",
1922
'GS://mybucket/myfile.csv',
2023
5,
2124
'gs//mybucket/myfile.csv',

spec/type_aliases/objectstore_s3uri_spec.rb

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,9 @@
1616
describe 'rejects other values' do
1717
[
1818
'',
19+
"\ns3://bucket-name/path",
20+
"\ns3://bucket-name/path\n",
21+
"s3://bucket-name/path\n",
1922
'S3://bucket-name/path',
2023
3,
2124
's3:/bucket-name/path',

spec/type_aliases/unixpath_spec.rb

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,9 @@
1919
{ 'foo' => 'bar' },
2020
{},
2121
'',
22+
"\n/var/tmp",
23+
"\n/var/tmp\n",
24+
"/var/tmp\n",
2225
'C:/whatever',
2326
'\\var\\tmp',
2427
'\\Users/hc/wksp/stdlib',

spec/type_aliases/windowspath_spec.rb

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,9 @@
1818
[nil, nil],
1919
{ 'foo' => 'bar' },
2020
{},
21+
"\nC:\\",
22+
"\nC:\\\n",
23+
"C:\\\n",
2124
'',
2225
'httds://notquiteright.org',
2326
'/usr2/username/bin:/usr/local/bin:/usr/bin:.',

types/base32.pp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
11
# Type to match base32 String
2-
type Stdlib::Base32 = Pattern[/^[a-z2-7]+={,6}$/, /^[A-Z2-7]+={,6}$/]
2+
type Stdlib::Base32 = Pattern[/\A[a-z2-7]+={,6}\z/, /\A[A-Z2-7]+={,6}\z/]

types/base64.pp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
11
# Type to match base64 String
2-
type Stdlib::Base64 = Pattern[/^[a-zA-Z0-9\/\+]+={,2}$/]
2+
type Stdlib::Base64 = Pattern[/\A[a-zA-Z0-9\/\+]+={,2}\z/]

types/filemode.pp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
11
# See `man chmod.1` for the regular expression for symbolic mode
2-
type Stdlib::Filemode = Pattern[/^(([0-7]{1,4})|(([ugoa]*([-+=]([rwxXst]*|[ugo]))+|[-+=][0-7]+)(,([ugoa]*([-+=]([rwxXst]*|[ugo]))+|[-+=][0-7]+))*))$/]
2+
type Stdlib::Filemode = Pattern[/\A(([0-7]{1,4})|(([ugoa]*([-+=]([rwxXst]*|[ugo]))+|[-+=][0-7]+)(,([ugoa]*([-+=]([rwxXst]*|[ugo]))+|[-+=][0-7]+))*))\z/]

types/filesource.pp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
Stdlib::Absolutepath,
44
Stdlib::HTTPUrl,
55
Pattern[
6-
/^file:\/\/\/([^\/\0]+(\/)?)+$/,
7-
/^puppet:\/\/(([\w-]+\.?)+)?\/([^\/\0]+(\/)?)+$/,
6+
/\Afile:\/\/\/([^\n\/\0]+(\/)?)+\z/,
7+
/\Apuppet:\/\/(([\w-]+\.?)+)?\/([^\n\/\0]+(\/)?)+\z/,
88
],
99
]

types/fqdn.pp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
type Stdlib::Fqdn = Pattern[/^(([a-zA-Z0-9]|[a-zA-Z0-9][a-zA-Z0-9\-]*[a-zA-Z0-9])\.)*([A-Za-z0-9]|[A-Za-z0-9][A-Za-z0-9\-]*[A-Za-z0-9])$/]
1+
type Stdlib::Fqdn = Pattern[/\A(([a-zA-Z0-9]|[a-zA-Z0-9][a-zA-Z0-9\-]*[a-zA-Z0-9])\.)*([A-Za-z0-9]|[A-Za-z0-9][A-Za-z0-9\-]*[A-Za-z0-9])\z/]

types/httpsurl.pp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
type Stdlib::HTTPSUrl = Pattern[/(?i:^https:\/\/)/]
1+
type Stdlib::HTTPSUrl = Pattern[/(?i:\Ahttps:\/\/.*\z)/]

types/httpurl.pp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
type Stdlib::HTTPUrl = Pattern[/(?i:^https?:\/\/)/]
1+
type Stdlib::HTTPUrl = Pattern[/(?i:\Ahttps?:\/\/.*\z)/]

types/mac.pp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
# A type for a MAC address
22
type Stdlib::MAC = Pattern[
3-
/^([0-9A-Fa-f]{2}[:-]){5}([0-9A-Fa-f]{2})$/,
4-
/^([0-9A-Fa-f]{2}[:-]){19}([0-9A-Fa-f]{2})$/
3+
/\A([0-9A-Fa-f]{2}[:-]){5}([0-9A-Fa-f]{2})\z/,
4+
/\A([0-9A-Fa-f]{2}[:-]){19}([0-9A-Fa-f]{2})\z/
55
]

types/objectstore/gsuri.pp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
1-
type Stdlib::ObjectStore::GSUri = Pattern[/^gs:\/\//]
1+
type Stdlib::ObjectStore::GSUri = Pattern[/\Ags:\/\/.*\z/]
22

types/objectstore/s3uri.pp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
type Stdlib::ObjectStore::S3Uri = Pattern[/^s3:\/\//]
1+
type Stdlib::ObjectStore::S3Uri = Pattern[/\As3:\/\/.*\z/]

types/unixpath.pp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
11
# this regex rejects any path component that does not start with "/" or is NUL
2-
type Stdlib::Unixpath = Pattern[/^\/([^\/\0]+\/*)*$/]
2+
type Stdlib::Unixpath = Pattern[/\A\/([^\n\/\0]+\/*)*\z/]

types/windowspath.pp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
type Stdlib::Windowspath = Pattern[/^(([a-zA-Z]:[\\\/])|([\\\/][\\\/][^\\\/]+[\\\/][^\\\/]+)|([\\\/][\\\/]\?[\\\/][^\\\/]+))/]
1+
type Stdlib::Windowspath = Pattern[/\A(([a-zA-Z]:[\\\/])|([\\\/][\\\/][^\\\/]+[\\\/][^\\\/]+)|([\\\/][\\\/]\?[\\\/][^\\\/]+)).*\z/]

0 commit comments

Comments
 (0)