Skip to content

Commit 1e57be4

Browse files
committed
feat: expand the dataset name regex to allow periods
1 parent 9bceb6f commit 1e57be4

File tree

4 files changed

+56
-5
lines changed

4 files changed

+56
-5
lines changed

src/DataSets.jl

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -106,8 +106,9 @@ end
106106
const DATASET_NAME_REGEX_STRING = raw"""
107107
[[:alnum:]]
108108
(?:
109-
[-[:alnum:]_] |
110-
/ (?=[[:alnum:]])
109+
[-[:alnum:]_] |
110+
\.(?=[[:alnum:]]) |
111+
\/ (?=[[:alnum:]])
111112
)*
112113
"""
113114
const DATASET_NAME_REGEX = Regex("^\n$(DATASET_NAME_REGEX_STRING)\n\$", "x")

test/dataset-names-invalid.txt

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,23 @@
11
a b
2-
a.b
32
a/b/
43
a//b
54
/a/b
65
a/-
76
a/ _/b
87
a/-a
98
a/-1
9+
.a
10+
..a
11+
a.
12+
a..
13+
.a.
14+
a..b
15+
.abc
16+
abc.
17+
abc/.def
18+
abc/def.
19+
a./b
20+
a.-
21+
_._
22+
a._b
23+
a.-b

test/dataset-names-valid.txt

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,3 +14,11 @@ a/1
1414
1-2-3
1515
x_-__
1616
a---
17+
a.b
18+
a.b
19+
abc.def
20+
abc/def.ghi
21+
abc-def.ghi_jkl
22+
a.b.c
23+
a_.c
24+
foo__-.csv

test/runtests.jl

Lines changed: 30 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -105,19 +105,47 @@ end
105105
@testset "Data set name parsing" begin
106106
@testset "Valid names" begin
107107
valid_names = load_list("dataset-names-valid.txt")
108-
@test length(valid_names) == 16
108+
@test !isempty(valid_names)
109109
@testset "Valid name: $name" for name in valid_names
110110
@test DataSets.check_dataset_name(name) === nothing
111111
@test DataSets._split_dataspec(name) == (name, nothing, nothing)
112+
# Also test that the name is still valid when it appears as part of
113+
# a path elements.
114+
let path_name = "foo/$(name)"
115+
@test DataSets.check_dataset_name(path_name) === nothing
116+
@test DataSets._split_dataspec(path_name) == (path_name, nothing, nothing)
117+
end
118+
let path_name = "$(name)/foo"
119+
@test DataSets.check_dataset_name(path_name) === nothing
120+
@test DataSets._split_dataspec(path_name) == (path_name, nothing, nothing)
121+
end
122+
let path_name = "foo/$(name)/bar"
123+
@test DataSets.check_dataset_name(path_name) === nothing
124+
@test DataSets._split_dataspec(path_name) == (path_name, nothing, nothing)
125+
end
112126
end
113127
end
114128

115129
@testset "Invalid names" begin
116130
invalid_names = load_list("dataset-names-invalid.txt")
117-
@test length(invalid_names) == 9
131+
@test !isempty(invalid_names)
118132
@testset "Invalid name: $name" for name in invalid_names
119133
@test_throws ErrorException DataSets.check_dataset_name(name)
120134
@test DataSets._split_dataspec(name) == (nothing, nothing, nothing)
135+
# Also test that the name is still invalid when it appears as part of
136+
# a path elements.
137+
let path_name = "foo/$(name)"
138+
@test_throws ErrorException DataSets.check_dataset_name(path_name) === nothing
139+
@test DataSets._split_dataspec(path_name) == (nothing, nothing, nothing)
140+
end
141+
let path_name = "$(name)/foo"
142+
@test_throws ErrorException DataSets.check_dataset_name(path_name) === nothing
143+
@test DataSets._split_dataspec(path_name) == (nothing, nothing, nothing)
144+
end
145+
let path_name = "foo/$(name)/bar"
146+
@test_throws ErrorException DataSets.check_dataset_name(path_name) === nothing
147+
@test DataSets._split_dataspec(path_name) == (nothing, nothing, nothing)
148+
end
121149
end
122150
end
123151
end

0 commit comments

Comments
 (0)