html icon indicating copy to clipboard operation
html copied to clipboard

Should custom validity error message treat \r as newline?

Open sefeng211 opened this issue 1 year ago • 1 comments

What is the issue with the HTML Standard?

A test snippet can be found at https://jsfiddle.net/naw7qxzf/

Currently Safari treats \r as newline, but Chrome doesn't. Looks like the spec only asks UAs to display this message, so this is left as an undefined behaviour.

sefeng211 avatar May 09 '24 14:05 sefeng211

I think it should match the title attribute. Per https://software.hixie.ch/utilities/js/live-dom-viewer/?.%3Cscript%3E%0Adocument.body.title%20%3D%20%22Line%5CrLine2%5CnLine3%22%0A%3C%2Fscript%3E it seems that all browsers support \r as newline there.

However, https://html.spec.whatwg.org/#the-title-attribute does not say that. I guess we should fix that?

Further testing shows \r\n is a single newline as well, which is somewhat expected.

annevk avatar May 13 '24 09:05 annevk

That makes sense. alert uses https://infra.spec.whatwg.org/#normalize-newlines, maybe we should reuse it?

sefeng211 avatar May 13 '24 17:05 sefeng211

Sounds good to me. Want to PR?

annevk avatar May 14 '24 07:05 annevk