Skip to content

Commit

Permalink
Fix int parsing (issue #41)
Browse files Browse the repository at this point in the history
  • Loading branch information
nico202 committed Nov 28, 2017
1 parent 9fc0d13 commit 3c6808c
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 6 deletions.
20 changes: 14 additions & 6 deletions src/constructor.jl
Original file line number Diff line number Diff line change
Expand Up @@ -193,12 +193,20 @@ function construct_yaml_int(constructor::Constructor, node::Node)
return value
end

if length(value) > 2 && value[1] == '0' && (value[2] == 'x' || value[2] == 'X')
return parse(Int, value[3:end], 16)
elseif length(value) > 1 && value[1] == '0'
return parse(Int, value, 8)
else
return parse(Int, value, 10)
try
if length(value) > 2 && value[1] == '0' && (value[2] == 'x' || value[2] == 'X')
return parse(Int, value[3:end], 16)
elseif length(value) > 1 && value[1] == '0'
return parse(Int, value, 8)
else
return parse(Int, value, 10)
end
catch y
if isa(y, ArgumentError)
return value
else
error("Could not decode int, failed with error $(y)")
end
end
end

Expand Down
3 changes: 3 additions & 0 deletions test/issue41.data
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
ISSBN: 0189123
dec: 189123
oct: 01123
1 change: 1 addition & 0 deletions test/issue41.expected
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Dict{Any,Any}("ISSBN" => "0189123", "dec" => 189123, "oct" => 595)
1 change: 1 addition & 0 deletions test/runtests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ const tests = [
"issue30",
"issue36",
"issue39",
"issue41"
"cartesian",
"ar1",
"ar1_cartesian"
Expand Down

0 comments on commit 3c6808c

Please sign in to comment.