Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.javascript > #21883

Re: Broken example on w3schools.com?

Message-ID <3249832.hYQsY692ZD@PointedEars.de> (permalink)
From Thomas 'PointedEars' Lahn <PointedEars@web.de>
Organization PointedEars Software (PES)
Date 2013-11-03 23:32 +0100
Subject Re: Broken example on w3schools.com?
Newsgroups comp.lang.javascript
References (2 earlier) <wrednc2y0uIAtOvPnZ2dnUVZ5v-dnZ2d@giganews.com> <031120131053367515%timstreater@greenbee.net> <52763025$0$6641$9b4e6d93@newsspool2.arcor-online.net> <lo2dncUZ99ZUPuvPnZ2dnUVZ5sudnZ2d@giganews.com> <0.14de356e0b8944a153ab.20131103212144GMT.87sivdji53.fsf@bsb.me.uk>

Show all headers | View raw


Ben Bacarisse wrote:

> "Robert Crandal" <noreply2me@yahoo.com> writes:
>> "Martin Honnen" <mahotrash@yahoo.de> wrote:
>>> Press F12 to open the developer tools and check whether Chrome shows
>>> some error message in the console.
>>
>> Okay, I pressed F12.  The first message I saw was:
>>        "Uncaught SyntaxError: Unexpected token ILLEGAL".
>>
>> Then, when I tried pressing the input button there is a message in the
>> console that says:
>>       "Uncaught SyntaxError: getElements is not defined".
> 
> I get similar errors using Gnome's browser (stupidly called Web).  The
> problem is some erroneous characters (hex A0) in the script element.

The characters themselves are not erroneous; “White space characters may 
occur between any two tokens and at the start or end of input” in 
ECMAScript, and they are defined in §7.2 as

| WhiteSpace ::
|  <TAB>
|  <VT>
|  <FF>
|  <SP>
|  <NBSP>
|  <BOM>
|  <USP>

Very likely the actual problem here is that the white-space characters are 
not properly encoded, or rather, as you pointed out, that a proper character 
encoding for the source code has not been declared.  

This can be tested: If you write code containing NO-BREAK SPACE outside of 
string literals in the Chrome Dev Console, V8 would execute the code without 
syntax error, and if you encodeURIComponent() it the result will contain 
“%C2%A0” (so the NO-BREAK SPACE is not converted to SPACE before execution).

> These result in, first, a syntax error and later, when the button is
> pressed, an undefined function (getElements).
> 
> Why these are there is a mystery.

I got bitten by those when I copy-pasted space-indented code from postings 
viewed in my newsreader, KNode.  Apparently my KNode uses NO-BREAK SPACE in 
order to prevent the line-break at this position.  Eclipse editors show 
these as syntax error (JSDT even though it per ECMAScript they are not), but 
I still would prefer KNode to copy those characters as SPACE to the 
clipboard.

> The URL in question is
> 
> http://www.w3schools.com/jsref/tryjsref_doc_getelementsbytagname.htm
> 
> which is sent without any indication of the character encoding.  Hex A0
> are, most likely, non-breaking spaces encoding in Windows-1252.  If I
> force my browser to see the page as Windows-1252, it all works.

Good catch.  The site is relying on that with a missing declaration of 
character encoding (neither in the HTTP header nor in the document) the 
content will be considered ISO-8859-1/Windows-1252-encoded as specified by 
HTTP/1.1.  However, it is equally possible that per the document 
specification (or whim of the developers) it is considered UTF-8-encoded 
first instead, and then the octet sequence A0 alone does _not_ encode U+00A0 
NO-BREAK SPACE; that character would have to be encoded as C2 A0 instead.

The encoding error is made visible with “�”s (U+FFFD REPLACEMENT CHARACTER) 
in the “Network” tab of Chrome Dev Tools when you select the request for the 
HTML document and then the “Response” sub-tab.  However, my Chromium and 
Chrome for Linux ignore that encoding error.
 
> Looks like more junk from a junk-filled site.

ACK.

-- 
PointedEars

Twitter: @PointedEars2
Please do not Cc: me. / Bitte keine Kopien per E-Mail.

Back to comp.lang.javascript | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread


Thread

Broken example on w3schools.com? "Robert Crandal" <noreply2me@yahoo.com> - 2013-11-03 01:36 -0700
  Re: Broken example on w3schools.com? "Jukka K. Korpela" <jkorpela@cs.tut.fi> - 2013-11-03 10:59 +0200
    Re: Broken example on w3schools.com? "Robert Crandal" <noreply2me@yahoo.com> - 2013-11-03 02:27 -0700
  Re: Broken example on w3schools.com? Martin Honnen <mahotrash@yahoo.de> - 2013-11-03 10:53 +0100
    Re: Broken example on w3schools.com? "Robert Crandal" <noreply2me@yahoo.com> - 2013-11-03 03:46 -0700
      Re: Broken example on w3schools.com? Tim Streater <timstreater@greenbee.net> - 2013-11-03 10:53 +0000
        Re: Broken example on w3schools.com? Martin Honnen <mahotrash@yahoo.de> - 2013-11-03 12:14 +0100
          Re: Broken example on w3schools.com? Tim Streater <timstreater@greenbee.net> - 2013-11-03 11:29 +0000
          Re: Broken example on w3schools.com? "Robert Crandal" <noreply2me@yahoo.com> - 2013-11-03 12:28 -0700
            Re: Broken example on w3schools.com? Thomas 'PointedEars' Lahn <PointedEars@web.de> - 2013-11-03 20:49 +0100
              Re: Broken example on w3schools.com? "Robert Crandal" <noreply2me@yahoo.com> - 2013-11-03 14:29 -0700
            Re: Broken example on w3schools.com? Ben Bacarisse <ben.usenet@bsb.me.uk> - 2013-11-03 21:21 +0000
              Re: Broken example on w3schools.com? "Robert Crandal" <noreply2me@yahoo.com> - 2013-11-03 15:10 -0700
              Re: Broken example on w3schools.com? Thomas 'PointedEars' Lahn <PointedEars@web.de> - 2013-11-03 23:32 +0100
      Re: Broken example on w3schools.com? Thomas 'PointedEars' Lahn <PointedEars@web.de> - 2013-11-03 13:26 +0100
      Re: Broken example on w3schools.com? Dr.Kral@nyc.rr.com - 2013-11-03 16:35 -0500
        Re: Broken example on w3schools.com? Thomas 'PointedEars' Lahn <PointedEars@web.de> - 2013-11-04 01:15 +0100

csiph-web