Bug 1335905 - Switch to indexOf instead of RegExp draft
authorFirefox <manotejmeka@gmail.com>
Fri, 31 Mar 2017 11:47:53 -0400
changeset 554463 33b00c6356c490ffd64bfe0611fce3e62e554852
parent 502517 583c5cb21b9ca35a1a91d3b4c18a7cc43d6d719e
child 622336 063346b92f5905fe2fe8059c38778bc6980d6dc6
push id51932
push userbmo:manotejmeka@gmail.com
push dateFri, 31 Mar 2017 15:48:43 +0000
bugs1335905
milestone55.0a1
Bug 1335905 - Switch to indexOf instead of RegExp MozReview-Commit-ID: 7yk8SeCrPAP
browser/components/preferences/in-content/findInPage.js
--- a/browser/components/preferences/in-content/findInPage.js
+++ b/browser/components/preferences/in-content/findInPage.js
@@ -110,26 +110,25 @@ var gSearchResultsPane = {
    *    Concatination of textNodes's text content
    *    Example:
    *    textNodes = [[This is ], [a], [n example]]
    *    nodeSizes = "This is an example"
    *    This is used when executing the regular expression
    * @param String searchPhrase
    *    word or words to search for
    * @returns boolean
-   *      Returns true when atleast one instance of search phrase is found, otherwise false
+   *      Returns true when at least one instance of search phrase is found, otherwise false
    */
   highlightMatches(textNodes, nodeSizes, textSearch, searchPhrase) {
-    let regExp = new RegExp(searchPhrase.replace(/[-\/\\^$*+?.()|[\]{}]/g, "\\$&"), "gi");
-    let result, indices = [];
-
-    while ((result = regExp.exec(textSearch))) {
-      indices.push(result.index);
+    let indices = [];
+    let i=-1;
+    while((i=textSearch.indexOf(searchPhrase,i+1)) >= 0) {
+      indices.push(i);
     }
-
+    
     // Looping through each spot the searchPhrase is found in the concatenated string
     for (let startValue of indices) {
       let endValue = startValue + searchPhrase.length;
       let startNode = null;
       let endNode = null;
       let nodeStartIndex = null;
 
       // Determining the start and end node to highlight from
@@ -182,17 +181,17 @@ var gSearchResultsPane = {
 
   /**
    * Shows or hides content according to search input
    *
    * @param String event
    *    to search for filted query in
    */
   searchFunction(event) {
-    let query = event.target.value.trim();
+    let query = event.target.value.trim().toLowerCase();
     this.findSelection.removeAllRanges();
 
     let srHeader = document.getElementById("header-searchResults");
 
     if (query) {
       // Showing the Search Results Tag
       gotoPref("paneSearchResults");
 
@@ -256,17 +255,17 @@ var gSearchResultsPane = {
    *      Returns true when found in at least one childNode, false otherwise
    */
   searchWithinNode(nodeObject, searchPhrase) {
     let matchesFound = false;
     if (nodeObject.childElementCount == 0) {
       let simpleTextNodes = this.textNodeDescendants(nodeObject);
 
       for (let node of simpleTextNodes) {
-        let result = this.highlightMatches([node], [node.length], node.textContent, searchPhrase);
+        let result = this.highlightMatches([node], [node.length], node.textContent.toLowerCase(), searchPhrase);
         matchesFound = matchesFound || result;
       }
 
       //  Collecting data from boxObject
       let nodeSizes = [];
       let allNodeText = "";
       let runningSize = 0;
       let labelResult = false;
@@ -275,17 +274,17 @@ var gSearchResultsPane = {
 
       for (let node of accessKeyTextNodes) {
         runningSize += node.textContent.length;
         allNodeText += node.textContent;
         nodeSizes.push(runningSize);
       }
 
       // Access key are presented
-      let complexTextNodesResult = this.highlightMatches(accessKeyTextNodes, nodeSizes, allNodeText, searchPhrase);
+      let complexTextNodesResult = this.highlightMatches(accessKeyTextNodes, nodeSizes, allNodeText.toLowerCase(), searchPhrase);
 
       //  Searching some elements, such as xul:button, have a 'label' attribute that contains the user-visible text.
       if (nodeObject.getAttribute("label")) {
         labelResult = this.stringMatchesFilters(nodeObject.getAttribute("label"), searchPhrase);
       }
 
       //  Searching some elements, such as xul:label, store their user-visible text in a "value" attribute.
       if (nodeObject.getAttribute("value")) {