Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion lib/rdoc/generator/template/json_index/js/searcher.js
Original file line number Diff line number Diff line change
Expand Up @@ -57,10 +57,14 @@ Searcher.prototype = new function() {
}

function buildRegexps(queries) {
// A small minority of older browsers don't have RegExp.escape
// but it's not worth including a complex polyfill.
var escape = RegExp.escape || function(s) { return s };

return queries.map(function(query) {
var pattern = [];
for (var i = 0; i < query.length; i++) {
var char = RegExp.escape(query[i]);
var char = escape(query[i]);
pattern.push('([' + char + '])([^' + char + ']*?)');
}
return new RegExp(pattern.join(''), 'i');
Expand Down
7 changes: 0 additions & 7 deletions test/rdoc/rdoc_generator_json_index_searcher_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,6 @@ class RDocGeneratorJsonIndexSearcherTest < Test::Unit::TestCase
def setup
@context = MiniRacer::Context.new

# Add RegExp.escape polyfill to avoid `RegExp.escape is not a function` error
@context.eval(<<~JS)
RegExp.escape = function(string) {
return string.replace(/[.*+?^${}()|[\\]\\\\]/g, '\\\\$&');
};
JS

searcher_js_path = File.expand_path(
'../../lib/rdoc/generator/template/json_index/js/searcher.js',
__dir__
Expand Down
Loading