Skip to content

Commit dc5a2db

Browse files
authored
Merge pull request #2144 from Urgau/gha-logs-polgit-regexp-escape
Polyfill `RegExp.escape` for older web-browser
2 parents b130fc4 + 4d71983 commit dc5a2db

File tree

1 file changed

+8
-1
lines changed

1 file changed

+8
-1
lines changed

src/gha_logs.rs

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -302,6 +302,13 @@ body {{
302302
html = html.replace(/##\[warning\]/g, () =>
303303
`<span class="warning-marker">##[warning]</span>`
304304
);
305+
306+
// pre-5. Polyfill the recently (2025) added `RegExp.escape` function.
307+
// Inspired by the former MDN section on escaping:
308+
// https://web.archive.org/web/20230806114646/https://developer.mozilla.org/en-US/docs/Web/JavaScript/Guide/Regular_expressions#escaping
309+
const escapeRegExp = RegExp.escape || function(string) {{
310+
return string.replace(/[.*+?^${{}}()|[\]\\/]/g, "\\$&");
311+
}};
305312
306313
// 5. Add anchors around some paths
307314
// Detailed examples of what the regex does is at https://regex101.com/r/vCnx9Y/2
@@ -319,7 +326,7 @@ body {{
319326
const pathRegex = new RegExp(
320327
"(?<boundary_start>[^a-zA-Z0-9.\\/])"
321328
+ "(?<inner>(?:[\\\/]?(?:checkout[\\\/])?(?<path>(?:"
322-
+ tree_roots.map(p => RegExp.escape(p)).join("|")
329+
+ tree_roots.map(p => escapeRegExp(p)).join("|")
323330
+ ")(?:[\\\/][a-zA-Z0-9_$\\\-.\\\/]+)?))"
324331
+ "(?::(?<line>[0-9]+):(?<col>[0-9]+))?)(?<boundary_end>[^a-zA-Z0-9.])",
325332
"g"

0 commit comments

Comments
 (0)