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

YAML fixes #4838

Closed
wants to merge 31 commits into from
Closed
Changes from 1 commit
Commits
Show all changes
31 commits
Select commit Hold shift + click to select a range
d55225d
Make YAML behave like the YAML 1.1 spec, fixes #3101, fixes #4384, an…
jwaldrip Aug 28, 2017
f3c89b4
make suggested changes
jwaldrip Aug 28, 2017
b607b65
update from_yaml to match the changes in to_yaml
jwaldrip Aug 29, 2017
b6a2e09
reserved values performance
jwaldrip Aug 29, 2017
f14198b
raise with a location
jwaldrip Aug 29, 2017
8346108
add todo
jwaldrip Aug 29, 2017
016dfd4
format
jwaldrip Aug 29, 2017
d6886fc
use case
jwaldrip Aug 29, 2017
d11fd05
Merge branch 'master' of https://github.com/crystal-lang/crystal into…
jwaldrip Aug 29, 2017
1bc96b5
use a char reader to give hints
jwaldrip Aug 30, 2017
ffccba4
use a case statement testing all the reserved cases
jwaldrip Aug 30, 2017
de2a1b7
add date to test case
jwaldrip Aug 30, 2017
d2476e2
use try's
jwaldrip Aug 30, 2017
922fa83
move logic into YAML::PullParser
jwaldrip Aug 31, 2017
47ee91c
use the method check
jwaldrip Sep 1, 2017
86f3f4b
dont raise
jwaldrip Sep 1, 2017
1faeb45
spelling & grammer
jwaldrip Sep 6, 2017
f5fc600
Merge branch 'yaml-spec' of github.com:jwaldrip/crystal into yaml-spec
jwaldrip Sep 6, 2017
0c605a8
Merge branch 'master' of github.com:jwaldrip/crystal into yaml-spec
jwaldrip Sep 6, 2017
cf95b76
re-inline specs
jwaldrip Sep 7, 2017
5a90882
remove checks
jwaldrip Sep 8, 2017
b3f6436
make suggested changes
jwaldrip Sep 8, 2017
3157fab
more spec changes
jwaldrip Sep 8, 2017
ceb9db9
fix quoted spec
jwaldrip Sep 8, 2017
e3df0d6
inline bool checks
jwaldrip Sep 10, 2017
50d5705
return false, remove parens
jwaldrip Sep 10, 2017
e2c8a1a
Merge branch 'master' of https://github.com/crystal-lang/crystal into…
jwaldrip Sep 10, 2017
69ee625
make `YAML.parse` support the core spec
jwaldrip Sep 16, 2017
31ca301
Merge branch 'yaml-spec' of github.com:jwaldrip/crystal into yaml-spec
jwaldrip Sep 16, 2017
6a5b820
Merge branch 'master' of https://github.com/crystal-lang/crystal into…
jwaldrip Sep 16, 2017
7a36cdc
Merge branch 'master' of https://github.com/crystal-lang/crystal into…
jwaldrip Sep 18, 2017
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
25 changes: 12 additions & 13 deletions src/yaml.cr
Original file line number Diff line number Diff line change
Expand Up @@ -168,18 +168,17 @@ module YAML
# Checks to see if the value is reserved
def self.reserved_value?(value)
return true if YAML::RESERVED_VALUES.includes?(value)
reserved = case {value[0]?, value[1]?, value[2]?, value[3]?, value[4]?}
when {.try(&.ascii_number?), .try(&.ascii_number?), .try(&.ascii_number?), .try(&.ascii_number?), '-'}
(Time::Format::ISO_8601_DATE_TIME.parse(value) rescue false)
when {.try(&.ascii_number?), _, _, _, _},
{'-', .try(&.ascii_number?), _, _, _},
{'+', .try(&.ascii_number?), _, _, _},
{'.', .try(&.ascii_number?), _, _, _},
{'-', '.', .try(&.ascii_number?), _, _},
{'+', '.', .try(&.ascii_number?), _, _}
clean_value = value.gsub('_', "")
clean_value.to_f64? || clean_value.to_i64?(prefix: true)
end
!reserved.nil?
case {value[0]?, value[1]?, value[2]?, value[3]?, value[4]?}
when {.try(&.ascii_number?), .try(&.ascii_number?), .try(&.ascii_number?), .try(&.ascii_number?), '-'}
!!(Time::Format::ISO_8601_DATE_TIME.parse(value) rescue false)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Parenthesis should not be needed here, because false is a Bool anyway

when {.try(&.ascii_number?), _, _, _, _},
{'-', .try(&.ascii_number?), _, _, _},
{'+', .try(&.ascii_number?), _, _, _},
{'.', .try(&.ascii_number?), _, _, _},
{'-', '.', .try(&.ascii_number?), _, _},
{'+', '.', .try(&.ascii_number?), _, _}
clean_value = value.gsub('_', "")
!!clean_value.to_f64? || !!clean_value.to_i64?(prefix: true)
end
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This method should return false if none of the cases matches.

end
end