-
Couldn't load subscription status.
- Fork 490
Escape html tags in innerHTML #4737
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
base: main
Are you sure you want to change the base?
Escape html tags in innerHTML #4737
Conversation
…rough an innerHTML attribute or not to properly escape them
…4319_escape-html-tags_contribute-main
|
@alexandrevryghem We reviewed this PR as a group in the developer meeting today, and we were wondering why you kept the escape all the way in |
|
By doing it this way we can easily customize which fields should still render HTML content, by simply updating the code in By updating the code like this, the abstract metadata field could still render links for example, but the other fields like titel and authors wouldn’t. if (injectedAsHTML && ! keyOrKeys.includes(‘dc.description.abstract’)) {
matches.push(Object.assign(new MetadataValue(), candidate, {
value: escape(candidate.value),
}));
} else {
matches.push(candidate as MetadataValue);
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@alexandrevryghem : Thanks for this PR as well. I tested this today alongside DSpace/DSpace#11345. It works well, and I can verify that HTML is now escaped (by default) the same across the application.
My only recommendation though is to consider a rename of the injectedAsHTML field (and simply call it escapeHTML or similar). I find the current name confusing because it doesn't accurately describe what happens when you pass in true. If you pass true, that doesn't cause the value to be injected elsewhere as HTML. Instead, a value of true causes any HTML to be escaped in the output.
That's my only minor comment. Beyond that, the rest looks good to me.
References
Description
Escapes HTML tags in content injected into the DOM using the
innerHTMLattribute.Instructions for Reviewers
List of changes in this PR:
injectedAsHTMLtotrue*Guidance for how to test or review this PR:
Checklist
mainbranch of code (unless it is a backport or is fixing an issue specific to an older branch).npm run lintnpm run check-circ-deps)package.json), I've made sure their licenses align with the DSpace BSD License based on the Licensing of Contributions documentation.