Skip to content

Stringex fix yaml reserved words2 - #201

Merged
rsl merged 2 commits into
rsl:masterfrom
giga811:stringex-fix-yaml-reserved-words2
Mar 13, 2018
Merged

rsl merged 2 commits into
rsl:masterfrom
giga811:stringex-fix-yaml-reserved-words2

Conversation

@giga811

@giga811 giga811 commented Mar 12, 2018

Copy link
Copy Markdown
Contributor

Hi again @rsl .

Seems my investigation was incomplete 😅 I missed another 2 parsing errors, sorry for the consecutive PRs 🙏
There is 2 fixes in this PR.

  1. quote on
  2. quote -

previous PR: #200

About quoting on

In yaml, on, off are also converted to true and false.
So I quoted all on occurences. Fortunately there was no off unidecode.

Example:

- ai
- oN
- o

[11] pry(main)> '0910'.to_i(16).chr.to_url
=> "ai"
[12] pry(main)> '0911'.to_i(16).chr.to_url
=> "true"
[13] pry(main)> '0912'.to_i(16).chr.to_url
=> "o"

About quoting -

And also yaml - - is parsing error. So also quoted -.
(- -- was not error)

Example:

- -
- '^'
- '***'
- --

It became nil in original unidecode gem and I guess stringex uses to_s to decode it and it became empty string "". '2040'.to_i(16).chr.to_ascii should become "-"

stringex to_ascii method:

[29] pry(main)> '2040'.to_i(16).chr.to_ascii
=> ""
[30] pry(main)> '2041'.to_i(16).chr.to_ascii
=> "^"
[31] pry(main)> '2042'.to_i(16).chr.to_ascii
=> "***"
[32] pry(main)> '2043'.to_i(16).chr.to_ascii
=> "--"

unidecode to_ascii method:

irb(main):096:0> '2040'.to_i(16).chr.to_ascii
=> "[nil]"

@giga811

giga811 commented Mar 12, 2018

Copy link
Copy Markdown
Contributor Author

The true/false thing seems only for on/off, yes/no
https://github.com/ruby/psych/blob/aec5469ef4a784e185e4e18ea542f3b5ef0f602f/lib/psych/scalar_scanner.rb#L52-L55

I skimmed all the files and seems these are the only yaml parsing errors.

I saw few symbols didn't have the quotations while original ascii version of the character was quoted. But seems - was the only symbol having error.

Quoted Ascii chars

- '='
- '>'
- '?'
- '@'

Some symbols aren't quoted:

- +
- -
- =
- (
- )

@rsl

rsl commented Mar 13, 2018

Copy link
Copy Markdown
Owner

please don't be sorry for consecutive PR. i appreciate this work. thanks!

@rsl

rsl commented Oct 26, 2021

Copy link
Copy Markdown
Owner

please explain? thanks

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants