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

Escape some html characters for alert component #448

Merged
merged 6 commits into from
Apr 2, 2019

Conversation

y-kkamil
Copy link

Description

Changes proposed in this pull request:

  • Add html characters encoding for Alert component
  • Move sanitisation functions to the new helper file for better readability

Related issue(s)
Fixes #447

@y-kkamil y-kkamil added this to the Sprint_Swinka_10 milestone Mar 29, 2019
@pekura pekura self-assigned this Mar 29, 2019
@parostatkiem-zz parostatkiem-zz self-assigned this Mar 29, 2019
Copy link
Contributor

@parostatkiem-zz parostatkiem-zz left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👌 Good idea with extracting the sanitisation to helpers

@y-kkamil
Copy link
Author

Oooops.. I found another issue - will fix it in a minute

Copy link
Contributor

@pekura pekura left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

See my comments plus this one:

We add global onclick handler based on elemId that we get from a MF. This can install a click listener to any element in the DOM tree of luigi - not good! We should add a special prefix to our alert tag IDs or use a different mechanism.

@@ -73,7 +72,8 @@

return Object.entries(links).reduce((acc, [key, content]) => {
const elemId = key;
const processedData = `<a id="${elemId}">${content.text}</a>`;
const escapedText = sanitizeHtml(content.text);
const processedData = `<a id="${elemId}">${escapedText}</a>`;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would escape/sanitize the key/elemId as well - it won't unlikely be misused (because it will be escaped in the text before so it is not found when we want to replace it with tag - but it won't work then.

@@ -73,7 +72,8 @@

return Object.entries(links).reduce((acc, [key, content]) => {
const elemId = key;
const processedData = `<a id="${elemId}">${content.text}</a>`;
const escapedText = sanitizeHtml(content.text);
const processedData = `<a id="${elemId}">${escapedText}</a>`;
const pattern = new RegExp(`({${key}})`, 'g');
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The key can contain characters that regexp interpretes (like '.' for example). The key needs to be passed here regexp-escaped! (See here https://stackoverflow.com/questions/3561493/is-there-a-regexp-escape-function-in-javascript/3561711).

@kwiatekus kwiatekus modified the milestones: Sprint_Swinka_10, Sprint_Swinka_11 Mar 29, 2019
@pekura pekura merged commit 9bd946c into SAP:master Apr 2, 2019
@pekura pekura deleted the escape-characters-for-alert branch April 2, 2019 12:44
@pekura pekura added the bug Something isn't working label Apr 12, 2019
stanleychh pushed a commit to stanleychh/luigi that referenced this pull request Dec 30, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Unescaped character may appear in the Alert component
4 participants