Skip to content

Commit c29506b

Browse files
committed
Skip over strings in Ruby files
1 parent 4827c46 commit c29506b

File tree

1 file changed

+53
-0
lines changed
  • crates/oxide/src/extractor/pre_processors

1 file changed

+53
-0
lines changed

crates/oxide/src/extractor/pre_processors/ruby.rs

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,50 @@ impl PreProcessor for Ruby {
7777

7878
// Ruby extraction
7979
while cursor.pos < len {
80+
match cursor.curr {
81+
b'"' => {
82+
cursor.advance();
83+
84+
while cursor.pos < len {
85+
match cursor.curr {
86+
// Escaped character, skip ahead to the next character
87+
b'\\' => cursor.advance_twice(),
88+
89+
// End of the string
90+
b'"' => break,
91+
92+
// Everything else is valid
93+
_ => cursor.advance(),
94+
};
95+
}
96+
97+
cursor.advance();
98+
continue;
99+
},
100+
101+
b'\'' => {
102+
cursor.advance();
103+
104+
while cursor.pos < len {
105+
match cursor.curr {
106+
// Escaped character, skip ahead to the next character
107+
b'\\' => cursor.advance_twice(),
108+
109+
// End of the string
110+
b'\'' => break,
111+
112+
// Everything else is valid
113+
_ => cursor.advance(),
114+
};
115+
}
116+
117+
cursor.advance();
118+
continue;
119+
},
120+
121+
_ => {}
122+
}
123+
80124
// Looking for `%w` or `%W`
81125
if cursor.curr != b'%' && !matches!(cursor.next, b'w' | b'W') {
82126
cursor.advance();
@@ -179,6 +223,13 @@ mod tests {
179223
// The nested delimiters evaluated to a flat array of strings
180224
// (not nested array).
181225
(r#"%w[foo[bar baz]qux]"#, r#"%w foo[bar baz]qux "#),
226+
227+
(r#""foo # bar""#, r#""foo # bar""#),
228+
(r#"'foo # bar'"#, r#"'foo # bar'"#),
229+
(
230+
r#"def call = tag.span "Foo", class: %w[rounded-full h-0.75 w-0.75]"#,
231+
r#"def call = tag.span "Foo", class: %w rounded-full h-0.75 w-0.75 "#
232+
),
182233
] {
183234
Ruby::test(input, expected);
184235
}
@@ -211,6 +262,8 @@ mod tests {
211262
"%w(flex data-[state=pending]:bg-(--my-color) flex-col)",
212263
vec!["flex", "data-[state=pending]:bg-(--my-color)", "flex-col"],
213264
),
265+
(r#""foo # bar""#, vec!["foo", "bar"]),
266+
(r#"'foo # bar'"#, vec!["foo", "bar"]),
214267
] {
215268
Ruby::test_extract_contains(input, expected);
216269
}

0 commit comments

Comments
 (0)