Skip to content
This repository was archived by the owner on Apr 7, 2020. It is now read-only.

Commit aae6933

Browse files
JacobMarshallPPProLoser
authored andcommitted
Upstream improvements (#26)
* Fixes event triggering from within angular * Fix the gulpfile watchers * Add support for escaping highlight html
1 parent 7395951 commit aae6933

File tree

4 files changed

+41
-9
lines changed

4 files changed

+41
-9
lines changed

dist/mention.js

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,16 @@ angular.module('ui.mention').controller('uiMention', ["$element", "$scope", "$at
8181
};
8282
};
8383

84+
var temp = document.createElement('span');
85+
function parseContentAsText(content) {
86+
try {
87+
temp.textContent = content;
88+
return temp.innerHTML;
89+
} finally {
90+
temp.textContent = null;
91+
}
92+
}
93+
8494
/**
8595
* $mention.render()
8696
*
@@ -93,6 +103,8 @@ angular.module('ui.mention').controller('uiMention', ["$element", "$scope", "$at
93103
var html = arguments.length <= 0 || arguments[0] === undefined ? ngModel.$modelValue : arguments[0];
94104

95105
html = (html || '').toString();
106+
// Convert input to text, to prevent script injection/rich text
107+
html = parseContentAsText(html);
96108
_this2.mentions.forEach(function (mention) {
97109
html = html.replace(_this2.encode(mention), _this2.highlight(mention));
98110
});
@@ -284,7 +296,9 @@ angular.module('ui.mention').controller('uiMention', ["$element", "$scope", "$at
284296
_this2.cancel();
285297
}
286298

287-
$scope.$apply();
299+
if (!$scope.$$phase) {
300+
$scope.$apply();
301+
}
288302
});
289303

290304
$element.on('keydown', function (event) {
@@ -311,7 +325,9 @@ angular.module('ui.mention').controller('uiMention', ["$element", "$scope", "$at
311325
_this2.moved = true;
312326
event.preventDefault();
313327

314-
$scope.$apply();
328+
if (!$scope.$$phase) {
329+
$scope.$apply();
330+
}
315331
});
316332

317333
this.onMouseup = (function (event) {

dist/mention.min.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

gulpfile.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -32,13 +32,13 @@ gulp.task('default', ['scripts']);
3232
gulp.task('example', ['scripts:example', 'styles:example']);
3333

3434
gulp.task('watch', function(){
35-
gulp.watch(paths.scripts.src, 'scripts');
36-
gulp.watch(paths.styles.src, 'styles');
35+
gulp.watch(paths.scripts.src, ['scripts']);
36+
gulp.watch(paths.styles.src, ['styles']);
3737
});
3838

3939
gulp.task('watch:example', function(){
40-
gulp.watch(paths.example.scripts.src, 'scripts:example');
41-
gulp.watch(paths.example.styles.src, 'styles:example');
40+
gulp.watch(paths.example.scripts.src, ['scripts:example']);
41+
gulp.watch(paths.example.styles.src, ['styles:example']);
4242
});
4343

4444
gulp.task('scripts', scripts(paths.scripts));

src/mentionController.es6.js

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,16 @@ angular.module('ui.mention')
5959
};
6060
};
6161

62+
var temp = document.createElement('span');
63+
function parseContentAsText(content) {
64+
try {
65+
temp.textContent = content;
66+
return temp.innerHTML;
67+
} finally {
68+
temp.textContent = null;
69+
}
70+
}
71+
6272
/**
6373
* $mention.render()
6474
*
@@ -69,6 +79,8 @@ angular.module('ui.mention')
6979
*/
7080
this.render = (html = ngModel.$modelValue) => {
7181
html = (html || '').toString();
82+
// Convert input to text, to prevent script injection/rich text
83+
html = parseContentAsText(html);
7284
this.mentions.forEach( mention => {
7385
html = html.replace(this.encode(mention), this.highlight(mention));
7486
});
@@ -257,7 +269,9 @@ angular.module('ui.mention')
257269
this.cancel();
258270
}
259271

260-
$scope.$apply();
272+
if (!$scope.$$phase) {
273+
$scope.$apply();
274+
}
261275
});
262276

263277
$element.on('keydown', event => {
@@ -282,7 +296,9 @@ angular.module('ui.mention')
282296
this.moved = true;
283297
event.preventDefault();
284298

285-
$scope.$apply();
299+
if (!$scope.$$phase) {
300+
$scope.$apply();
301+
}
286302
});
287303

288304

0 commit comments

Comments
 (0)