Skip to content

Commit 1b4261c

Browse files
straight-shootaRX14
authored andcommittedMar 5, 2018
Fix YAML core schema parses integer 0 (#5774)
Parsing scalar `0` previously returned a string (`"0"`) instead of integer. This fixes it by adding a special case for `0`. Also adds a few specs for zero values (though binary, octal, hex were not broken).
1 parent 163c0cb commit 1b4261c

File tree

2 files changed

+5
-0
lines changed

2 files changed

+5
-0
lines changed
 

‎spec/std/yaml/schema/core_spec.cr

+4
Original file line numberDiff line numberDiff line change
@@ -94,17 +94,21 @@ describe YAML::Schema::Core do
9494
end
9595

9696
# integer (base 10)
97+
it_parses_scalar "0", 0
9798
it_parses_scalar "123", 123
9899
it_parses_scalar "+123", 123
99100
it_parses_scalar "-123", -123
100101

101102
# integer (binary)
103+
it_parses_scalar "0b0", 0
102104
it_parses_scalar "0b10110", 0b10110
103105

104106
# integer (octal)
107+
it_parses_scalar "00", 0
105108
it_parses_scalar "0123", 0o123
106109

107110
# integer (hex)
111+
it_parses_scalar "0x0", 0
108112
it_parses_scalar "0x123abc", 0x123abc
109113
it_parses_scalar "-0x123abc", -0x123abc
110114

‎src/yaml/schema/core.cr

+1
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,7 @@ module YAML::Schema::Core
8484
value = parse_float?(string)
8585
return value || string
8686
when .starts_with?('0')
87+
return 0_i64 if string.size == 1
8788
value = string.to_i64?(base: 8, prefix: true)
8889
return value || string
8990
when .starts_with?('-'),

0 commit comments

Comments
 (0)
Please sign in to comment.