-
Notifications
You must be signed in to change notification settings - Fork 96
Escape characters on xml attributes #217
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
Open
dt-jean-baptiste-lemee
wants to merge
1
commit into
WebReflection:main
Choose a base branch
from
DiliTrust:escape-charaters-on-xml-attributes
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
'use strict'; | ||
const {VALUE} = require('../shared/symbols.js'); | ||
const {emptyAttributes} = require('../shared/attributes.js'); | ||
const {escape} = require('../shared/text-escaper.js'); | ||
const {Attr} = require('./attr.js'); | ||
|
||
const QUOTE = /"/g; | ||
|
||
/** | ||
* @implements globalThis.Attr | ||
*/ | ||
class XMLAttr extends Attr { | ||
constructor(ownerDocument, name, value = '') { | ||
super(ownerDocument, name, value); | ||
} | ||
|
||
toString() { | ||
const {name, [VALUE]: value} = this; | ||
return emptyAttributes.has(name) && !value ? | ||
name : `${name}="${escape(value).replace(QUOTE, """)}"`; | ||
} | ||
} | ||
exports.XMLAttr = XMLAttr |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
import {VALUE} from '../shared/symbols.js'; | ||
import {emptyAttributes} from '../shared/attributes.js'; | ||
import {escape} from '../shared/text-escaper.js'; | ||
import {Attr} from './attr.js'; | ||
|
||
const QUOTE = /"/g; | ||
|
||
/** | ||
* @implements globalThis.Attr | ||
*/ | ||
export class XMLAttr extends Attr { | ||
constructor(ownerDocument, name, value = '') { | ||
super(ownerDocument, name, value); | ||
} | ||
|
||
toString() { | ||
const {name, [VALUE]: value} = this; | ||
return emptyAttributes.has(name) && !value ? | ||
name : `${name}="${escape(value).replace(QUOTE, """)}"`; | ||
} | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
/** | ||
* @implements globalThis.Attr | ||
*/ | ||
export class XMLAttr extends Attr implements globalThis.Attr { | ||
} | ||
import { Attr } from "./attr.js"; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
I think
ignoreCase
could be remove in favor ofisXml
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.
so this MR is just about using
isXml
instead ofignoreCase
? I am not sure what I am looking at in here, but I am sure the MR could be way simpler without adding oddly-cased fields (XML is XML, not Xml) and slow/XSS-prone transformers as commentedUh oh!
There was an error while loading. Please reload this page.
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.
nop, this PR is about fixing this issue : #216 I think the test speaks for itself. I commented this, just to say that we could remove ignoreCase boolean since it has to ignoreCase only on non-xml so it's redondant here
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.
I think I've named it as such due XHTML but again I am not sure why we need to change that ... it could be breaking if anyone out there brand-check that property.
Uh oh!
There was an error while loading. Please reload this page.
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.
I've renamed
isXml
toisXML
andXmlAttr
toXMLAttr
Tell me if there's anything else I could improve on this MR
Uh oh!
There was an error while loading. Please reload this page.
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.
There is a regression on
"
. I've push a solution but again I'm chainingescape
and areplace
. I wondering why don't we escape all html entities (https://www.w3schools.com/html/html_entities.asp) onAttr.toString
through theescape
function ? This way we do not needXMLAttr
norMime.isXML
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.
I think you are better off with JSDOM there ... it's 100% standard, and 100% slower than LinkeDOM
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.
😆 I'm trying to switch from JSDom to linkedom because it is 100 000% slower (JSDom takes sometime 5minutes to manage xml document when Linkedom takes 1second on the same document !) But yes, still we need a bit more "standardization". I don't think it's a bad idea for linkedom, but your the boss, it's your choice. We can use our fork. Thank for this lib and the work, it's huge.
Uh oh!
There was an error while loading. Please reload this page.
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.
to be fair, XML is not the main target here and you are suggesting XML related changes and paths that would slow the common use case by far, as example suggesting to escape all html entities ... I understand this is valuable for your business but this project is about perf ... perf for most common use cases, which is not XML, so apologies if my answers are not the most welcoming one, but I am trying to preserve the original idea of this project which is: work for most common cases and as fast as possible ... your quest feels a bit against that initial/original goal, hence my nitpicking in here. Hope you can understand, and hope your fork will work great for your use case too!