diff --git a/packages/html-reporter/src/index.ts b/packages/html-reporter/src/index.ts
index d15fac64..6713e3f7 100644
--- a/packages/html-reporter/src/index.ts
+++ b/packages/html-reporter/src/index.ts
@@ -4,6 +4,23 @@ import {IReporter, JsonReporter} from "@jscpd/finder";
import {copySync, writeFileSync, readFileSync} from "fs-extra";
import {green, red} from "colors/safe";
+function escapeHtml(value) {
+ if (typeof value !== 'string') {
+ return value;
+ }
+ return value.replace(/[&<>`"'\/]/g, function(result) {
+ return {
+ '&': '&',
+ '<': '<',
+ '>': '>',
+ '`': '`',
+ '"': '"',
+ "'": ''',
+ '/': '/',
+ }[result];
+ })
+}
+
export default class HtmlReporter implements IReporter {
constructor(private options: IOptions) {
}
@@ -11,6 +28,9 @@ export default class HtmlReporter implements IReporter {
public report(clones: IClone[], statistic: IStatistic): void {
const jsonReporter = new JsonReporter(this.options);
const json = jsonReporter.generateJson(clones, statistic);
+ json.duplicates.forEach(item => {
+ item.fragment = escapeHtml(item.fragment);
+ });
if (this.options.output) {
const src = join(__dirname, '../html/');
const destination = join(this.options.output, 'html/');