Dev.Opera - Follow the standards, break the rulesDev.Opera - Follow the standards, break the rules

Login

Lost password?

Forums » Article Discussions

Discuss the articles posted on Dev.Opera.

Note: You need to login to post in the forums. if you don't have an account you first need to sign up.

By garethr anchor Thursday, 6. December 2007, 15:19:07

JSON Configuration for JavaScript

If you're working in a web development team with developers alongside designers, and you want to give the designers an easy way to change the variable parts of the application without the risk of breaking things, an external configuration file is a great idea, and JSON (JavaScript Object Notation) is a perfect format in which to store this data. In this article, Gareth Rushgrove shows you how.

( Read the article )

By hallvors O anchor Saturday, 8. December 2007, 10:18:24

avatarSmall nit: "class" is a reserved word in ES, I'm not sure if any UA would actually throw an error on "Object.array[0].class" but I think it shouldn't be used like this in demo/tutorial code.

By v1c anchor Thursday, 22. May 2008, 15:10:34

avatarOpera 9.27 for Windows International (latest available) cannot load JSON script json2.js (taken from http://www.JSON.org/json2.js):

Inline script compilation
Syntax error while loading: line 181 of linked script at file://localhost/C:/TMP/json2.js :
var cx = /[\u0000\u00ad\u0600-\u0604\u070f\u17b4\u17
------------------^

Other browsers (IE, FF) are working with this script library without errors. Minimal HTML page with script causing problem is:

<html>
<head>
<script type="text/javascript">
var cx=/[\u0000\u00ad\u0600-\u0604\u070f\u17b4\u17b5\u200c-\u200f\u2028-\u202f\u2060-\u206f\ufeff\ufff0-\uffff]/g;
</script>
</head>
<body>
</body>
</html>

When I make shorter regular expression, all works fine (for example, var cx=/[\u00ad\u0600-\u0604\u070f\u17b4\u17b5\u200c-\u200f\u2028-\u202f\u2060-\u206f\ufeff\ufff0-\uffff]/g; is OK).

Bug report is unavailable... Have someone tested this with earlier (or latest 9.5 beta) versions of Opera?

By kskander anchor Tuesday, 1. July 2008, 15:05:18

avatarIt seems like Opera stumbles on the 'raw' regular expression syntax.

I replaced the troublesome lines in json2.js below:

var cx = /[\u0000\u00ad\u0600-\u0604\u070f\u17b4\u17b5\u200c-\u200f\u2028-\u202f\u2060-\u206f\ufeff\ufff0-\uffff]/g,
escapeable = /[\\\"\x00-\x1f\x7f-\x9f\u00ad\u0600-\u0604\u070f\u17b4\u17b5\u200c-\u200f\u2028-\u202f\u2060-\u206f\ufeff\ufff0-\uffff]/g,
gap,

with:

var cx = new RegExp('/[\\u0000\\u00ad\\u0600-\\u0604\\u070f\\u17b4\\u17b5\\u200c-\\u200f\\u2028-\\u202f\\u2060-\\u206f\\ufeff\\ufff0-\\uffff]/g');
var escapeable = new RegExp('/[\\\\\\"\\x00-\\x1f\\x7f-\\x9f\\u00ad\\u0600-\\u0604\\u070f\\u17b4\\u17b5\\u200c-\\u200f\\u2028-\\u202f\\u2060-\\u206f\\ufeff\\ufff0-\\uffff]/g');
var gap,
[...]

Seems to work on FF/IE/Opera so far.

Cheers.

By saifshaik anchor Monday, 9. March 2009, 08:11:42

avatarThanks man the above thing worked for opera 9.27.

By KeithBoynton anchor Wednesday, 29. April 2009, 19:52:16

avatarActually, that's almost a fix. While it does allow it to load correctly, it doesn't allow it "work" correctly.

The variable escapeable is incorrectly spelt, it should read...

var cx = new RegExp('/[\\u0000\\u00ad\\u0600-\\u0604\\u070f\\u17b4\\u17b5\\u200c-\\u200f\\u2028-\\u202f\\u2060-\\u206f\\ufeff\\ufff0-\\uffff]/g');
var escapable = new RegExp('/[\\\\\\"\\x00-\\x1f\\x7f-\\x9f\\u00ad\\u0600-\\u0604\\u070f\\u17b4\\u17b5\\u200c-\\u200f\\u2028-\\u202f\\u2060-\\u206f\\ufeff\\ufff0-\\uffff]/g');


Still, kudos for the fix :wink:

Moderators: pepelsbey | dstorey | mcx | operadev | chrismills | shwetankdixit | brucelawson | iheni | andreasbovens | zibin | mollydotcom