Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Possible fix for int parsing #45

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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