diff --git a/lib/rdoc/generator/template/json_index/js/searcher.js b/lib/rdoc/generator/template/json_index/js/searcher.js index 8f03f67a93..74accb7460 100644 --- a/lib/rdoc/generator/template/json_index/js/searcher.js +++ b/lib/rdoc/generator/template/json_index/js/searcher.js @@ -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'); diff --git a/test/rdoc/rdoc_generator_json_index_searcher_test.rb b/test/rdoc/rdoc_generator_json_index_searcher_test.rb index 36613e57c4..065ea04e17 100644 --- a/test/rdoc/rdoc_generator_json_index_searcher_test.rb +++ b/test/rdoc/rdoc_generator_json_index_searcher_test.rb @@ -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__