Last Comment Bug 410628 - script does not work in UTF-16 svg file
: script does not work in UTF-16 svg file
Status: REOPENED
:
Product: Core
Classification: Components
Component: SVG (show other bugs)
: Trunk
: x86 Windows Vista
: -- normal with 2 votes (vote)
: ---
Assigned To: Nobody; OK to take it and work on it
:
Mentors:
http://www.mapviewsvg.com/examples/ma...
Depends on:
Blocks:
  Show dependency treegraph
 
Reported: 2008-01-03 05:05 PST by Armin Müller
Modified: 2009-01-05 07:00 PST (History)
7 users (show)
See Also:
Crash Signature:
(edit)
QA Whiteboard:
Iteration: ---
Points: ---
Has Regression Range: ---
Has STR: ---


Attachments
example which shows the problem (96.13 KB, application/x-zip-compressed)
2008-01-11 03:57 PST, Armin Müller
no flags Details
patch (814 bytes, patch)
2008-01-11 06:21 PST, Robert Longson
no flags Details | Diff | Review

Description Armin Müller 2008-01-03 05:05:08 PST
User-Agent:       Mozilla/5.0 (Windows; U; Windows NT 6.0; en-US; rv:1.9b3pre) Gecko/2008010211 Minefield/3.0b3pre
Build Identifier: Mozilla/5.0 (Windows; U; Windows NT 6.0; en-US; rv:1.9b3pre) Gecko/2008010211 Minefield/3.0b3pre

there is an iso-8859-1 javascript referenced in an UTF-16 svg file with
<script xlink:href="viewboxtile.js" type="text/ecmascript" charset="iso-8859-1"/>

This produce the error "Error: illegal character"

Works OK with IE, Opera and Safari 

Reproducible: Always

Steps to Reproduce:
1. start URL
2. show Error console
3.
Actual Results:  
Error "Error: illegal character"

Expected Results:  
No error

works with IE, Opera and Safari. Do not work with FF2 and FF3
Comment 1 Robert Longson 2008-01-10 09:57:31 PST
Does this happen if you have a UTF-16 xhtml file and reference the same iso-8859-1 javascript file? If so you should probably change the component to something more appropriate.
Comment 2 Armin Müller 2008-01-11 00:25:48 PST
All file types (SVG, html) in the project are in UTF-16. All javascripts are in iso-8859-1. It is no problem to use the javascripts from inside the html files but only from inside the SVG files.
Comment 3 Robert Longson 2008-01-11 00:35:41 PST
Are they xhtml or html. It's different parsers in mozilla. Could you try an xhtml file please?
Comment 4 Armin Müller 2008-01-11 00:58:50 PST
The html files are html not xhtml, but with this files i do not have problems. The SVG files are xml files. With this xml files i have the problem.
Comment 5 Robert Longson 2008-01-11 02:32:19 PST
Could you convert try converting and serving one of your html files as xhtml so it is an xml file and confirm that that does not work please?
Comment 6 Armin Müller 2008-01-11 03:57:14 PST
Created attachment 296512 [details]
example which shows the problem

if using index.html or index.svg then there are javascript errors. Using viewboxtileUTF.js instead of viewboxtile.js solve the problem
Comment 7 Armin Müller 2008-01-11 04:03:21 PST
Robert sorry but i did not understand why i shall change my html file into xhtml, because the error is in the SVG file not in the html.
I have attached an example, where you can see the problem.
If you start index.html in FF you will get two errors because viewboxtile.js (iso-8859-1) could not be readed from inside map.svg (UTF-16). If you use viewboxtileUTF.js (UTF-16) instead you do not have this errors. The same thing, when you use index.svg. This example only use one svg file (UTF-16) and some js files (iso-8859-1).
If you use this example in Opera or IE then you have no errors
Comment 8 Robert Longson 2008-01-11 04:32:06 PST
> Created an attachment (id=296512) [details]
> example which shows the problem
> 
> if using index.html or index.svg then there are javascript errors. Using
> viewboxtileUTF.js instead of viewboxtile.js solve the problem
> 

Are you now saying you get the same error with html files as svg files. In comment 4 you seemed to imply that html files worked.

Comment 9 Robert Longson 2008-01-11 04:34:53 PST
(In reply to comment #7)
> Robert sorry but i did not understand why i shall change my html file into
> xhtml, because the error is in the SVG file not in the html.

I'm trying to get you to determine whether this issue affects SVG only or SVG and XHTML or SVG and XHTML and HTML. Knowing that will make it more likely this bug gets fixed.

You now seem to be saying that this is not an SVG specific issue as it affects html files too. Is that correct?
Comment 10 Armin Müller 2008-01-11 04:46:38 PST
Sorry my english is not the best. You have misunderstood my comment #7. The error is only with javascripts which are referenced in SVG files. 
The example index.html is an example where several SVG files are embedded in a html file. Here some javascript files are referenced in index.html (They work fine) one javascript is referenced in map.svg (This javascript did not work). Index.svg is an example which only use SVG. All javascripts are referenced in index.svg (none of these javascripts work).  

As i have seen in my project the issue affects SVG not HTML. I have no informations about xhtml.
Comment 11 Robert Longson 2008-01-11 05:23:58 PST
Can you investigate xhtml and determine whether it is affected?
Comment 12 Armin Müller 2008-01-11 05:45:52 PST
I can not convert index.html without code changes into xhtml because some things are not currently compatible with xhtml. But after removing incompatible parts it seems that i can reference and use javascript files (iso-8859-1) inside a xhtml file (UTF-16) without errors. So i would say the issue does not affect xhtml. 
Comment 13 Robert Longson 2008-01-11 06:21:17 PST
Created attachment 296532 [details] [diff] [review]
patch

Thanks Armin, your investigation was very helpful in tracking down the problem.
Comment 14 tor 2008-01-11 09:52:11 PST
While this would make the testcase work, if I read the spec right it seems that svg:script doesn't have a charset attribute.
Comment 15 Robert Longson 2008-01-11 09:56:49 PST
Oops. I guess that makes this invalid then. Seems that SVG ought to do that though.
Comment 16 Doug Schepers 2008-01-11 15:22:35 PST
(In reply to comment #15)
> Oops. I guess that makes this invalid then.

No, the bug report is still valid.  SVG says that unknown attributes should be ignored, so specifying the charset attribute should have no effect.


>  Seems that SVG ought to do that though.

I agree. <svg:script> should have a @charset.  I have raised a bug report in our own bug tracker. [ http://www.w3.org/Bugs/Public/show_bug.cgi?id=5362 ]

Comment 17 Doug Schepers 2008-01-11 15:42:56 PST
oops... spoke too soon.  @charset is probably best left out. See SVG bug #5362.

Bug is still valid, though.
Comment 18 Robert Longson 2008-01-11 16:22:21 PST
(In reply to comment #16)
> 
> No, the bug report is still valid.  SVG says that unknown attributes should be
> ignored, so specifying the charset attribute should have no effect.
> 

The charset attribute is currently ignored by firefox which is why the testcases in this bug don't work.
Comment 19 Robert Longson 2008-01-11 16:24:03 PST
Armin, do you specify a charset in the mime type when you serve the javascript file?
Comment 20 Robert Longson 2008-01-13 10:39:17 PST
I think you need to serve the javascript with something like...

Content-Type: text/javascript; charset=iso-8859-1
Comment 21 Armin Müller 2008-01-14 01:37:14 PST
Robert, this is the line in the svg file
<script xlink:href="viewboxtile.js" type="text/ecmascript"
charset="iso-8859-1"/>
Comment 22 Robert Longson 2008-01-14 02:02:43 PST
I'm not talking about the svg file any more Armin. The charset attribute does not exist on script elements in SVG and so is ignored. Apparently the machine serving the javascript must indicate the charset of the file in the http Content-Type of its response.
Comment 23 Armin Müller 2008-01-14 02:14:37 PST
Robert, this i do not understand. I have the problem only if i work locally. Where can i have a look if my machine indicate the charset in the http Content type of a lcal file?
Comment 24 Armin Müller 2008-01-14 02:16:48 PST
Forget my comment #23. The problem is locally and on server. 
Comment 25 Robert Longson 2008-01-14 02:21:18 PST
Local files are an issue. It would be best if you raised this particular concern in http://www.w3.org/Bugs/Public/show_bug.cgi?id=5362

The SVG specification drives our implementation, at the moment we do what it says, if you can get the specification changed our implementation can follow.

Configuring the Content-Type depends on what server you are using Apache, Tomcat or whatever, each has different rules. Perhaps a newsgroups appropriate to the server you are using could answer that question.
Comment 26 Armin Müller 2008-01-14 04:24:44 PST
Sorry, i do not understand why the www server should be the reaon for this problem. And i see nothing in the SVG specification which prevent running javascripts with a different codepage from inside a svg.

- i have a javascript file (iso-8859-1)
- i call it from inside a html4 file (UTF16): all works fine
- i call it from inside a xhtml file (UTF16): all works fine
- i call it from inside a svg file (UTF16): nothing works

For me this is a bug. 
Comment 27 Robert Longson 2008-01-14 04:30:48 PST
SVG does allow javascript with a different codepage to the SVG file. At the moment you must do this via specifying a Content-Type in the server.

Read this: http://www.w3.org/TR/SVG11/script.html#ScriptElement

The only attribute a script element has is type. It does NOT have a charset attribute.

html and xhtml script elements on the other hand DO have a charset attribute.

If you want to discuss whether the specification should have a charset attribute you should do so in http://www.w3.org/Bugs/Public/show_bug.cgi?id=5362
Comment 28 Armin Müller 2008-01-14 04:50:52 PST
Robert, ok  i think i understand the fact with the charset attribut. I think Doug has already noticed this.
Just Reply your comment #27 in my words:
This mean if i have a SVG (UTF16) then my javascript must be UTF16 too.

But then i do not understand the following example which works well with FF
- i have a javascript file (UTF16)
- i call it from inside a svg file (iso-8859-1): all works fine

As i see the problem only occurs in direction SVG(UTF16) -> javascript(iso-8859-1) not this direction  SVG(iso-8859-1) -> javascript(UTF16). And this i do not see in http://www.w3.org/TR/SVG11/script.html#ScriptElement 
Comment 29 Robert Longson 2008-01-14 05:13:59 PST
(In reply to comment #28)
> Robert, ok  i think i understand the fact with the charset attribut. I think
> Doug has already noticed this.
> Just Reply your comment #27 in my words:
> This mean if i have a SVG (UTF16) then my javascript must be UTF16 too.

No, you can have UTF16 svg and iso-8859-1 javascript if you make the http server return a charset in the Content-Type of the http header. 

> 
> But then i do not understand the following example which works well with FF
> - i have a javascript file (UTF16)
> - i call it from inside a svg file (iso-8859-1): all works fine
> 
> As i see the problem only occurs in direction SVG(UTF16) ->
> javascript(iso-8859-1) not this direction  SVG(iso-8859-1) ->
> javascript(UTF16). And this i do not see in
> http://www.w3.org/TR/SVG11/script.html#ScriptElement 
> 

The default encoding is iso-8859-1 so the javascript will not work unless either it has that encoding or you put the Content-Type in the HTTP header. Perhaps you are specifying the SVG content type in some way.


Comment 30 Robert Longson 2008-01-14 05:35:59 PST
Your SVG has this <?xml version="1.0" encoding="utf-16" standalone="no"?> to identify its content type which is presumably why it works even though it is not served with a content-type set.
Comment 31 Armin Müller 2008-01-14 05:38:29 PST
(In reply to comment #29)
> No, you can have UTF16 svg and iso-8859-1 javascript if you make the http
> server return a charset in the Content-Type of the http header. 

I did not know a possibilty to define the used charset in a javascript file. I know this for server based scripts such as PHP or ASP but not for javascript. 


Comment 32 Robert Longson 2008-01-14 05:42:12 PST
You cannot do it in the javascript file itself only the server of the javascript file can do that or as you say it can be done with PHP or ASP also if you wish.
Comment 33 Armin Müller 2008-01-14 05:45:00 PST
(In reply to comment #30)
> Your SVG has this <?xml version="1.0" encoding="utf-16" standalone="no"?> to
> identify its content type which is presumably why it works even though it is
> not served with a content-type set.
> 

These are my settings for my two examples SVG(UTF16) -> javascript(iso-8859-1) and SVG(iso-8859-1) -> javascript(UTF16)

- i have a javascript file (iso-8859-1 file format)
- i call it from inside a svg file (?xml version="1.0" encoding="utf-16" standalone="no"?)
=> nothing works

- i have a javascript file (UTF16 file format)
- i call it from inside a svg file (?xml version="1.0" encoding="iso-8859-1" standalone="no"?)
=> all works fine
Comment 34 Robert Longson 2008-01-14 05:59:40 PST
Do you get similar results with html and xhtml if you remove the charset attribute from the <script> element?
Comment 35 Armin Müller 2008-01-14 06:32:24 PST
I have now tested the following:

- i have a javascript file (utf-16 file format)
- i call it from inside a html file (utf-16 <meta http-equiv="content-type" content="text/html; charset=utf-16" />)

=> <script src="embfiles/variablen.js" language="JavaScript" type="text/javascript""> works
=> <script src="embfiles/variablen.js" language="JavaScript" type="text/javascript" charset="utf-16">works
=> <script src="embfiles/variablen.js" language="JavaScript" type="text/javascript" charset="iso-8859-1"> did not work

Comment 36 Robert Longson 2008-12-19 08:45:43 PST
Looks like the SVG working group declined to add a type attribute to the script object so this cannot be made to work within the confines of the SVG specification.
Comment 37 Jonathan Watt [:jwatt] (Away Jun. 27 - Jul. 13) 2009-01-05 03:03:47 PST
Doug just reopened http://www.w3.org/Bugs/Public/show_bug.cgi?id=5362 to consider whether the 'charset' attribute would be useful for local content. I'm not sure exactly what the preferred behavior is, but it seems sensible that the attribute should be used if the charset is not otherwise specified.
Comment 38 Boris Zbarsky [:bz] (Out June 25-July 6) 2009-01-05 06:42:42 PST
I'd assume the working group would clearly specify the exact behavior here, no?
Comment 39 Jonathan Watt [:jwatt] (Away Jun. 27 - Jul. 13) 2009-01-05 06:58:43 PST
Well I'm a member of the WG, and we'll try. ;-) I was CC'ing you guys to see if you had any comments on this and how you think it should work so the WG can get it right the first time.
Comment 40 Boris Zbarsky [:bz] (Out June 25-July 6) 2009-01-05 07:00:50 PST
You could look at what CSS specifies and then modify as needed for your use case, I guess.  You could also look at what HTML5 is doing and try to be compatible with that.  That might make the most sense.

Note You need to log in before you can comment on or make changes to this bug.