Skip to content

Commit 8b0520a

Browse files
committed
Ruby: Make strings greedy. Fixes #1048
1 parent b42fa77 commit 8b0520a

File tree

3 files changed

+9
-1
lines changed

3 files changed

+9
-1
lines changed

components/prism-ruby.js

+6
Original file line numberDiff line numberDiff line change
@@ -71,37 +71,43 @@
7171
Prism.languages.ruby.string = [
7272
{
7373
pattern: /%[qQiIwWxs]?([^a-zA-Z0-9\s\{\(\[<])(?:[^\\]|\\[\s\S])*?\1/,
74+
greedy: true,
7475
inside: {
7576
'interpolation': interpolation
7677
}
7778
},
7879
{
7980
pattern: /%[qQiIwWxs]?\((?:[^()\\]|\\[\s\S])*\)/,
81+
greedy: true,
8082
inside: {
8183
'interpolation': interpolation
8284
}
8385
},
8486
{
8587
// Here we need to specifically allow interpolation
8688
pattern: /%[qQiIwWxs]?\{(?:[^#{}\\]|#(?:\{[^}]+\})?|\\[\s\S])*\}/,
89+
greedy: true,
8790
inside: {
8891
'interpolation': interpolation
8992
}
9093
},
9194
{
9295
pattern: /%[qQiIwWxs]?\[(?:[^\[\]\\]|\\[\s\S])*\]/,
96+
greedy: true,
9397
inside: {
9498
'interpolation': interpolation
9599
}
96100
},
97101
{
98102
pattern: /%[qQiIwWxs]?<(?:[^<>\\]|\\[\s\S])*>/,
103+
greedy: true,
99104
inside: {
100105
'interpolation': interpolation
101106
}
102107
},
103108
{
104109
pattern: /("|')(#\{[^}]+\}|\\(?:\r?\n|\r)|\\?.)*?\1/,
110+
greedy: true,
105111
inside: {
106112
'interpolation': interpolation
107113
}

components/prism-ruby.min.js

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

tests/languages/ruby/string_feature.test

+2
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ bar'
77
"foo\
88
bar"
99

10+
"foo #bar"
1011
"foo #{ 42 } bar"
1112

1213
%!foo #{ 42 }!
@@ -44,6 +45,7 @@ bar"
4445
["string", ["\"foo\""]],
4546
["string", ["'foo\\\r\nbar'"]],
4647
["string", ["\"foo\\\r\nbar\""]],
48+
["string", ["\"foo #bar\""]],
4749
["string", [
4850
"\"foo ",
4951
["interpolation", [

0 commit comments

Comments
 (0)