fix(html_tag): encode url value of url-related attributes and skip escape/encode <style>#96
Conversation
|
@dailyrandomphoto |
4f294e9 to
2c91312
Compare
I have tested some cases and found no issues. |
|
Just found an edge case for responsive image <img srcset="elva-fairy-320w.jpg 320w,
elva-fairy-480w.jpg 480w,
elva-fairy-800w.jpg 800w"
sizes="(max-width: 320px) 280px,
(max-width: 480px) 440px,
800px"
src="elva-fairy-800w.jpg" alt="Elva dressed as a fairy">🤔 Let's see possible approaches:
|
This is the |
That's actually is the first regex I tried, but it's not applicable here because html_tag is not parsing a html. Essentially, the goal is just to avoid encoding the space in Anyway, the latest fix, while seems overcomplicating stuff, it's to preserve new lines. Frankly, I don't know if anyone actually wants it (new line) 😅 . Personally, I would just go for function handleSpace(str) {
return encodeURI(str).replace(/(%20)/g, ' ');
}
function handleSpaceNewLine(str) {
return encodeURI(str).replace(/(%20|%0A)/g, ' ');
}
function handleSpaceNewLineMinify(str) {
return encodeURI(str).replace(/%20/g, ' ').replace(/,(%0A|%0D%0A)*\s*/g, ',');
}
let data = `fóo.jpg 320w,
/foo/bár.jpeg 480w,
default.png`
console.log(handleSpace(data))
// f%C3%B3o.jpg 320w,%0A /foo/b%C3%A1r.jpeg 480w,%0A default.png
console.log(handleSpaceNewLine(data))
// f%C3%B3o.jpg 320w, /foo/b%C3%A1r.jpeg 480w, default.png
console.log(handleSpaceNewLineMinify(data))
// f%C3%B3o.jpg 320w,/foo/b%C3%A1r.jpeg 480w,default.png |
address #94 (comment) to support url value in data-* attributes (e.g. data-url,
data-src)cc @dailyrandomphoto
test case is already covered by