Skip to content

Commit

Permalink
- Fixed dsym unescaping. (mvz)
Browse files Browse the repository at this point in the history
[git-p4: depot-paths = "//src/ruby_parser/dev/": change = 13581]
  • Loading branch information
zenspider committed Nov 6, 2022
1 parent 8553cf6 commit c82ae7b
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 4 deletions.
15 changes: 11 additions & 4 deletions lib/ruby_lexer.rb
Original file line number Diff line number Diff line change
Expand Up @@ -232,7 +232,7 @@ def possibly_escape_string text, check
content = match[1]

if text =~ check then
content.gsub(ESC) { unescape $1 }
unescape_string content
else
content.gsub(/\\\\/, "\\").gsub(/\\\'/, "'")
end
Expand Down Expand Up @@ -590,9 +590,7 @@ def process_simple_string text
orig_line = lineno
self.lineno += text.count("\n")

str = text[1..-2]
.gsub(ESC) { unescape($1).b.force_encoding Encoding::UTF_8 }
str = str.b unless str.valid_encoding?
str = unescape_string text[1..-2]

result EXPR_END, :tSTRING, str, orig_line
end
Expand Down Expand Up @@ -817,6 +815,15 @@ def space_vs_beginning space_type, beg_type, fallback
end
end

def unescape_string str
str = str.gsub(ESC) { unescape($1).b.force_encoding Encoding::UTF_8 }
if str.valid_encoding?
str
else
str.b
end
end

def unescape s
r = ESCAPES[s]

Expand Down
13 changes: 13 additions & 0 deletions test/test_ruby_lexer.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3009,6 +3009,19 @@ def test_yylex_symbol_double_interp
:tSTRING_END, "\"", EXPR_LIT)
end

def test_yylex_symbol_double_escape_octal
setup_lexer ":\"Variet\\303\\240\""

adv = @lex.next_token
act_token, act_value = adv
act_value = act_value.first

assert_equal :tSYMBOL, act_token
assert_match EXPR_LIT, @lex.lex_state
# Force comparison of encodings
assert_equal "Varietà", act_value
end

def test_yylex_symbol_single
assert_lex3(":'symbol'",
nil,
Expand Down
7 changes: 7 additions & 0 deletions test/test_ruby_parser.rb
Original file line number Diff line number Diff line change
Expand Up @@ -826,6 +826,13 @@ def test_dsym_to_sym
assert_parse rb, pt
end

def test_dsym_esc_to_sym
rb = ':"Variet\303\240"'
pt = s(:lit, :Varietà)

assert_parse rb, pt
end

def test_empty
refute_parse ""
end
Expand Down

0 comments on commit c82ae7b

Please sign in to comment.