Skip to content

Commit

Permalink
Ruby: Make strings greedy. Fixes #1048
Browse files Browse the repository at this point in the history
  • Loading branch information
Golmote committed Nov 9, 2016
1 parent b42fa77 commit 8b0520a
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 1 deletion.
6 changes: 6 additions & 0 deletions components/prism-ruby.js
Original file line number Diff line number Diff line change
Expand Up @@ -71,37 +71,43 @@
Prism.languages.ruby.string = [
{
pattern: /%[qQiIwWxs]?([^a-zA-Z0-9\s\{\(\[<])(?:[^\\]|\\[\s\S])*?\1/,
greedy: true,
inside: {
'interpolation': interpolation
}
},
{
pattern: /%[qQiIwWxs]?\((?:[^()\\]|\\[\s\S])*\)/,
greedy: true,
inside: {
'interpolation': interpolation
}
},
{
// Here we need to specifically allow interpolation
pattern: /%[qQiIwWxs]?\{(?:[^#{}\\]|#(?:\{[^}]+\})?|\\[\s\S])*\}/,
greedy: true,
inside: {
'interpolation': interpolation
}
},
{
pattern: /%[qQiIwWxs]?\[(?:[^\[\]\\]|\\[\s\S])*\]/,
greedy: true,
inside: {
'interpolation': interpolation
}
},
{
pattern: /%[qQiIwWxs]?<(?:[^<>\\]|\\[\s\S])*>/,
greedy: true,
inside: {
'interpolation': interpolation
}
},
{
pattern: /("|')(#\{[^}]+\}|\\(?:\r?\n|\r)|\\?.)*?\1/,
greedy: true,
inside: {
'interpolation': interpolation
}
Expand Down
2 changes: 1 addition & 1 deletion components/prism-ruby.min.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions tests/languages/ruby/string_feature.test
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ bar'
"foo\
bar"

"foo #bar"
"foo #{ 42 } bar"

%!foo #{ 42 }!
Expand Down Expand Up @@ -44,6 +45,7 @@ bar"
["string", ["\"foo\""]],
["string", ["'foo\\\r\nbar'"]],
["string", ["\"foo\\\r\nbar\""]],
["string", ["\"foo #bar\""]],
["string", [
"\"foo ",
["interpolation", [
Expand Down

0 comments on commit 8b0520a

Please sign in to comment.