Skip to content

Commit 6d2c6fc

Browse files
committed
Search queries which start or end with punctuation (e.g. "Notorious B.I.G.") no longer fail when followed by additional punctuation.
1 parent 4d37adc commit 6d2c6fc

1 file changed

Lines changed: 3 additions & 3 deletions

File tree

public/javascripts/DV/helpers/search.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,6 @@ _.extend(DV.Schema.helpers, {
5050

5151
},
5252
highlightSearchResponses: function(){
53-
5453
var viewer = this.viewer;
5554
var response = viewer.searchResponse;
5655

@@ -74,11 +73,12 @@ _.extend(DV.Schema.helpers, {
7473

7574
// Replaces spaces in query with `\s+` to match newlines in textContent,
7675
// escape regex char contents (like "()"), and only match on word boundaries.
77-
var query = '\\b' + response.query.replace(/[-[\]{}()*+?.,\\^$|#]/g, "\\$&").replace(/\s+/g, '\\s+') + '\\b';
76+
var boundary = '(\\b|\\B)';
77+
var query = boundary + '('+response.query.replace(/[-[\]{}()*+?.,\\^$|#]/g, "\\$&").replace(/\s+/g, '\\s+')+')' + boundary;
7878
var textContent = this.viewer.$('.DV-textContents');
7979
var currentPageText = textContent.text();
8080
var pattern = new RegExp(query,"ig");
81-
var replacement = currentPageText.replace(pattern,'<span class="DV-searchMatch">$&</span>');
81+
var replacement = currentPageText.replace(pattern,'$1<span class="DV-searchMatch">$2</span>$3');
8282

8383
textContent.html(replacement);
8484

0 commit comments

Comments
 (0)