Skip to content

Commit 411615e

Browse files
committed
HTML encode after pattern matching to avoid breaking HTML entities
For example, < is encoded as &lt; but the lt() function matches and highlights that, which breaks the HTML entity.
1 parent b5b0b3d commit 411615e

File tree

1 file changed

+16
-5
lines changed

1 file changed

+16
-5
lines changed

dashboard/js/components/22.angular-smart-area-1.5.0.js

+16-5
Original file line numberDiff line numberDiff line change
@@ -300,24 +300,35 @@ angular.module('smartArea', [])
300300
* a cssClass specified.
301301
*/
302302
function highlightText(){
303-
var text = $scope.areaData,
304-
html = htmlEncode(text);
303+
var text = $scope.areaData;
304+
var cssClasses = [];
305305

306306
if(typeof($scope.areaConfig.autocomplete) === 'undefined' || $scope.areaConfig.autocomplete.length === 0){
307307
return;
308308
}
309309

310310
$scope.areaConfig.autocomplete.forEach(function(autoList){
311311
for(var i=0; i<autoList.words.length; i++){
312+
var cssId = cssClasses.length;
313+
cssClasses.push(autoList.cssClass);
312314
if(typeof(autoList.words[i]) === "string"){
313-
html = html.replace(new RegExp("([^\\w]|\\b)("+autoList.words[i]+")([^\\w]|\\b)", 'g'), '$1<span class="'+autoList.cssClass+'">$2</span>$3');
315+
text = text.replace(new RegExp("([^\\w]|\\b)("+autoList.words[i]+")([^\\w]|\\b)", 'g'), '$1§x'+cssId+'x§$2§/x' + cssId + 'x§$3');
314316
}else{
315-
html = html.replace(autoList.words[i], function(match){
316-
return '<span class="'+autoList.cssClass+'">'+match+'</span>';
317+
text = text.replace(autoList.words[i], function(match){
318+
return '§x' + cssId + 'x§'+match+'§/x' + cssId + 'x§';
317319
});
318320
}
319321
}
320322
});
323+
var html = htmlEncode(text);
324+
let changed;
325+
do {
326+
changed = false;
327+
html = html.replace(/§x(\d+)x§([\s\S]*?)§\/x\1x§/g, function(match, cssId, content) {
328+
changed = true;
329+
return '<span class="'+cssClasses[cssId]+'">'+content+'</span>';
330+
});
331+
} while (changed)
321332
// Add to the fakeArea
322333
$scope.fakeArea = $sce.trustAsHtml(html);
323334
}

0 commit comments

Comments
 (0)