Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Escaping helpers improvement and config fix of e2e app #2483

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 7 additions & 7 deletions core/src/utilities/helpers/escaping-helpers.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// Helper methods that deal with character escaping.
class EscapingHelpersClass {
sanitizeHtml(text) {
sanitizeHtml(text = '') {
return text
.replace(/&/g, '&')
.replace(/</g, '&lt;')
Expand All @@ -10,15 +10,15 @@ class EscapingHelpersClass {
.replace(/javascript:/g, '');
}

restoreSanitizedBrs(text) {
restoreSanitizedBrs(text = '') {
return text
.replace(/&lt;br\/&gt;/g, '<br>')
.replace(/&lt;br \/&gt;/g, '<br>')
.replace(/&lt;br&gt;/g, '<br>')
.replace(/&lt;br &gt;/g, '<br>');
}

restoreSanitizedElements(text) {
restoreSanitizedElements(text = '') {
let result = text;
const elements = ['i', 'b', 'br', 'mark', 'strong', 'em', 'small', 'del', 'ins', 'sub', 'sup'];

Expand Down Expand Up @@ -47,11 +47,11 @@ class EscapingHelpersClass {
return result;
}

sanatizeHtmlExceptTextFormatting(text) {
sanatizeHtmlExceptTextFormatting(text = '') {
return this.restoreSanitizedElements(this.sanitizeHtml(text));
}

sanitizeParam(param) {
sanitizeParam(param = '') {
return String(param)
.replace(/</g, '&lt;')
.replace(/>/g, '&gt;')
Expand All @@ -60,11 +60,11 @@ class EscapingHelpersClass {
.replace(/\//g, '&sol;');
}

escapeKeyForRegexp(str) {
escapeKeyForRegexp(str = '') {
return str.replace(/[\-\[\]\/\{\}\(\)\*\+\?\.\\\^\$\|]/g, '\\$&');
}

processTextAndLinks(text, links, uniqueID) {
processTextAndLinks(text = '', links, uniqueID) {
let sanitizedText = this.restoreSanitizedBrs(this.sanitizeHtml(text));
let initialValue = { sanitizedText, links: [] };

Expand Down
33 changes: 16 additions & 17 deletions core/test/utilities/helpers/escaping-helpers.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,37 +14,48 @@ describe('Escaping-helpers', () => {
sanitizedHtml2,
'This is text &lt;img src=&quot;http://url.to.file.which/not.exist&quot; onerror=alert(document.cookie); onclick=alert(document.cookie)&gt;&lt;br&gt;&lt;IMG SRC=j&amp;#X41vascript:alert(&#39;test2&#39;)&gt;&lt;br&gt;'
);
const sanitizedHtml3 = EscapingHelpers.sanitizeHtml();
assert.equal(sanitizedHtml3, '');
});

it('restoreSanitizedBrs', () => {
const text = '&lt;br&gt; &lt;br &gt; &lt;br /&gt; &lt;br/&gt;';
const restoredHtml = EscapingHelpers.restoreSanitizedBrs(text);
assert.equal(restoredHtml, '<br> <br> <br> <br>');
const restoredHtml2 = EscapingHelpers.restoreSanitizedBrs();
assert.equal(restoredHtml2, '');
});

it('restoreSanitizedElements', () => {
const text =
'&lt;br&gt; &lt;b &gt; &lt;del /&gt; &lt;i/&gt; &lt;strong&gt;';
const text = '&lt;br&gt; &lt;b &gt; &lt;del /&gt; &lt;i/&gt; &lt;strong&gt;';
const restoredHtml = EscapingHelpers.restoreSanitizedElements(text);
assert.equal(restoredHtml, '<br> <b> <del> <i> <strong>');
const restoredHtml2 = EscapingHelpers.restoreSanitizedElements();
assert.equal(restoredHtml2, '');
});

it('sanatizeHtmlExceptTextFormatting', () => {
const text = '<br> <b> <del> <i> <strong> <script>';
const restoredHtml = EscapingHelpers.sanatizeHtmlExceptTextFormatting(text);
assert.equal(restoredHtml, '<br> <b> <del> <i> <strong> &lt;script&gt;');
const restoredHtml2 = EscapingHelpers.sanatizeHtmlExceptTextFormatting();
assert.equal(restoredHtml2, '');
});

it('sanitizeParam', () => {
const param = '<>"\'/';
const sanitizedParam = EscapingHelpers.sanitizeParam(param);
assert.equal(sanitizedParam, '&lt;&gt;&quot;&#39;&sol;');
const sanitizedParam2 = EscapingHelpers.sanitizeParam();
assert.equal(sanitizedParam2, '');
});

it('escapeKeyForRegexp', () => {
const key = 'some/*/thing';
const escapedRegexp = EscapingHelpers.escapeKeyForRegexp(key);
assert.equal(escapedRegexp, 'some\\/\\*\\/thing');
const escapedRegexp2 = EscapingHelpers.escapeKeyForRegexp();
assert.equal(escapedRegexp2, '');
});

describe('processTextAndLinks', () => {
Expand Down Expand Up @@ -79,11 +90,7 @@ describe('Escaping-helpers', () => {
links: []
};

assert.deepEqual(
escapedTextAndLinks,
expectedResult,
'excaped text object with empty link array'
);
assert.deepEqual(escapedTextAndLinks, expectedResult, 'excaped text object with empty link array');
});

it('with links', () => {
Expand All @@ -102,11 +109,7 @@ describe('Escaping-helpers', () => {
const uniqueID = 1234567890;

// when
const escapedTextAndLinks = EscapingHelpers.processTextAndLinks(
text,
links,
uniqueID
);
const escapedTextAndLinks = EscapingHelpers.processTextAndLinks(text, links, uniqueID);

// then
const expectedResult = {
Expand All @@ -126,11 +129,7 @@ describe('Escaping-helpers', () => {
]
};

assert.deepEqual(
escapedTextAndLinks,
expectedResult,
'excaped text and links object'
);
assert.deepEqual(escapedTextAndLinks, expectedResult, 'excaped text and links object');
});
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -216,7 +216,13 @@ export const projectDetailNavStructure = projectId => [
viewUrl: '/sampleapp.html#/on-node-activation/conditionally-navigated',
openNodeInModal: true,
onNodeActivation: () => {
return Luigi.showConfirmationModal({}).then(() => true, () => false);
const settings = {
header: 'Confirmation',
body: 'Are you sure you want to do this?',
buttonConfirm: 'Yes',
buttonDismiss: 'No'
};
return Luigi.showConfirmationModal(settings).then(() => true, () => false);
}
}
]
Expand Down