Skip to content

Commit

Permalink
Merge pull request #302 from projectEndings/iss-293-ampersands
Browse files Browse the repository at this point in the history
Iss 293 ampersands
  • Loading branch information
joeytakeda authored May 6, 2024
2 parents e302356 + d66c7d6 commit 9974114
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 2 deletions.
7 changes: 5 additions & 2 deletions js/StaticSearch.js
Original file line number Diff line number Diff line change
Expand Up @@ -819,6 +819,8 @@ class StaticSearch{
//Then remove any leading or trailing apostrophes
strSearch = strSearch.replace(/(^'|'$)/g,'');

//Now escape ampersands.
strSearch = strSearch.replace(/&/g, '&');

//If we're not supporting phrasal searches, get rid of double quotes.
if (!this.allowPhrasal){
Expand Down Expand Up @@ -873,8 +875,9 @@ class StaticSearch{
this.addSearchItem(strSoFar, inPhrase);

// Now clear the queryBox and replace its contents
// By joining the normalized query
this.queryBox.value = this.normalizedQuery.join(" ");
// by joining the normalized query, and putting
// any ampersands back where they were.
this.queryBox.value = this.normalizedQuery.join(" ").replace(/&/, '&');


//We always want to handle the terms in order of
Expand Down
4 changes: 4 additions & 0 deletions test/badthings.html
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,10 @@ <h1>File with bad things in it</h1>

<p>One type of out-stretched: out-stretcht</p>
<p>Another type of out-stretched: out-ſtretcht</p>

<p>We need to check the correct handling of ampersands in genuine contexts, such as the name Marks &amp; Spencer.</p>

<p>But the same name might be written Marks &#x0026; Spencer, or Marks &#38; Spencer.</p>

<p>Now let's try some stuff that ought to be carefully sanitized
during indexing. This word should not appear in bold in the results: &lt;b&gt;bold&lt;/b&gt;.
Expand Down
14 changes: 14 additions & 0 deletions test/testJs/testJs.js
Original file line number Diff line number Diff line change
Expand Up @@ -218,6 +218,20 @@ tests.push({
}
});

//Phrasal search with ampersand.
tests.push({
setup: function () {
Sch.queryBox.value = '"Marks & Spencer"'
},
check: function (num) {
console.log('Search hook ' + num);
console.log('Testing results for the phrase "Marks & Spencer".');
checkResults({
docsFound: 1, contextsFound: 3, scoreTotal: 3
});
}
});

//Two MUST_CONTAINs with boolean flag.
tests.push({
setup: function () {
Expand Down

0 comments on commit 9974114

Please sign in to comment.