Skip to content

Commit edb2c97

Browse files
committed
Int parsing - Proposed fix for issue#41
1 parent f289e47 commit edb2c97

File tree

4 files changed

+21
-6
lines changed

4 files changed

+21
-6
lines changed

src/constructor.jl

+14-6
Original file line numberDiff line numberDiff line change
@@ -193,12 +193,20 @@ function construct_yaml_int(constructor::Constructor, node::Node)
193193
return value
194194
end
195195

196-
if length(value) > 2 && value[1] == '0' && (value[2] == 'x' || value[2] == 'X')
197-
return parse(Int, value[3:end], 16)
198-
elseif length(value) > 1 && value[1] == '0'
199-
return parse(Int, value, 8)
200-
else
201-
return parse(Int, value, 10)
196+
try
197+
if length(value) > 2 && value[1] == '0' && (value[2] == 'x' || value[2] == 'X')
198+
return parse(Int, value[3:end], 16)
199+
elseif length(value) > 1 && value[1] == '0'
200+
return parse(Int, value, 8)
201+
else
202+
return parse(Int, value, 10)
203+
end
204+
catch y
205+
if isa(y, ArgumentError)
206+
return value
207+
else
208+
error("Could not decode int, failed with error $(y)")
209+
end
202210
end
203211
end
204212

test/issue41.data

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
ISSBN: 0189123
2+
dec: 189123
3+
oct: 01123

test/issue41.expected

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Dict{Any,Any}("ISSBN" => "0189123", "dec" => 189123, "oct" => 595)

test/runtests.jl

+3
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,9 @@ const tests = [
3535
"escape_sequences",
3636
"issue15",
3737
"issue30",
38+
"issue36",
39+
"issue39",
40+
"issue41"
3841
"cartesian",
3942
"ar1",
4043
"ar1_cartesian"

0 commit comments

Comments
 (0)