Skip to content

Commit

Permalink
Escaping helpers improvment and config fix of e2e app (SAP#2483)
Browse files Browse the repository at this point in the history
  • Loading branch information
JohannesDoberer authored Jan 21, 2022
1 parent 4534264 commit da3f867
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 25 deletions.
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

0 comments on commit da3f867

Please sign in to comment.