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

http://mothereff.in/byte-counter pasting from clipboard changes line feeds #25

Open
GuiSim opened this issue Mar 12, 2014 · 2 comments
Open

Comments

@GuiSim
Copy link

GuiSim commented Mar 12, 2014

Hi!

I encountered an issue with http://mothereff.in/byte-counter.
I pasted a string containing a simple Windows line feeds (CR LF).

I expected the byte value to be 2 but the website displayed 1.
I then ran

    $("textarea").value.charCodeAt(0) 

This returned "10".
I expected it to return the same thing as

"\r\n".charCodeAt(0)

which is "13".

I am using Chrome Version 33.0.1750.146 m on Windows.
I had copied the text from Notepad++.

@mathiasbynens
Copy link
Owner

Browsers normalize the input in form elements. There is nothing I can do about this.

See http://www.whatwg.org/specs/web-apps/current-work/multipage/the-button-element.html#the-textarea-element:

The element’s API value is defined to be the element's raw value with the following transformation applied:

Replace every U+000D CARRIAGE RETURN U+000A LINE FEED (CRLF) character pair from the raw value with a single U+000A LINE FEED (LF) character.

Replace every remaining U+000D CARRIAGE RETURN character from the raw value with a single U+000A LINE FEED (LF) character.

The element's value is defined to be the element's raw value with the following transformation applied:

Replace every occurrence of a U+000D CARRIAGE RETURN (CR) character not followed by a U+000A LINE FEED (LF) character, and every occurrence of a U+000A LINE FEED (LF) character not preceded by a U+000D CARRIAGE RETURN (CR) character, by a two-character string consisting of a U+000D CARRIAGE RETURN U+000A LINE FEED (CRLF) character pair.

If the element's wrap attribute is in the Hard state, insert U+000D CARRIAGE RETURN U+000A LINE FEED (CRLF) character pairs into the string using a UA-defined algorithm so that each line has no more than character width characters. For the purposes of this requirement, lines are delimited by the start of the string, the end of the string, and U+000D CARRIAGE RETURN U+000A LINE FEED (CRLF) character pairs.

@GuiSim
Copy link
Author

GuiSim commented Mar 12, 2014

Thanks for the information and the detailed documentation.
I suggest that you add a simple note, perhaps whenever someone pastes a new line, mentioning this? This could avoid further confusion.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants