Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
659 views
in Technique[技术] by (71.8m points)

unicode - What is this INSANE space character??? (google chrome)

This is driving me absolutely, !&&%&$ insane... it defies everything that I can think of.

THIS character right here... "?"

In between these quotes... open google chrome and inspect. You will see its a  ... normal right? Now right click and actually view the source of this stack overflow page. It's a regular space... (also, the character I copied was an actual space).

I could understand if it's some kind of rich text editor or something, but in the raw html source is a regular space, so what gives?

Here's just with hitting the space key (which works fine)... " ".

You can even copy it and paste it everywhere and wreak havoc and make chrome put   everywhere. Even though whats copied in your clipboard is just a SPACE.

I have these stupid characters show up everywhere randomly in my website and I have no idea where they come from, or WHY is google converting a SPACE into a nbsp;

I have tried inspecting the actual character code and it's a regular space from all things I can find...

Every single method I try shows it as a NORMAL space... so what gives?

If i use ruby and do " ".ord I get 32. If i do it with the broken space I also get 32.

Please help me im losing my mind.

edit: you can prove this... view source on this page and you will see two empty " " like normal. Now look in console and only the one will be a  , yet the raw source is identical.

Image for people not using chrome (this is looking at this very post via chrome dev tools): enter image description here

Here's the HTML of the same text you see when you view source... no nbsp to be found.

enter image description here

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

When I view this page's source in Internet Explorer, or download it directly from the server and view it in a text editor, the first space character in question is formatted like this in the actual HTML:

THIS character right here... " "

Notice the   entity. That is Unicode codepoint U+00A0 NO-BREAK SPACE. Chrome is just being nice and re-formatting it as   when inspecting the HTML. But make no mistake, it is a real non-breaking space, not Unicode codepoint U+0020 SPACE like you are expecting. U+00A0 is visually displayed the same as U+0020, but they are semantically different characters.

The second space character in question is formatted like this in the actual HTML:

<p>Here's just with hitting the space key (which works fine)... <code>" "</code>.</p>

So it is Unicode codepoint U+0020 and not U+00A0. Viewing the raw hex data of this page confirms that:

screenshot showing non-breaking space

screenshot showing normal space


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...