Welcome to WebmasterWorld Guest from 54.167.213.22

Forum Moderators: open

Message Too Old, No Replies

Opera 9.2 9.1 9.0 JavaScript replace regex bug

     
8:52 am on Nov 1, 2010 (gmt 0)

WebmasterWorld Senior Member jab_creations is a WebmasterWorld Top Contributor of All Time 10+ Year Member



In my quest for backwards compatibility I've found an odd bug in Opera 9.0~9.2. I get a "Inline script compilation" error for my regular expression because it doesn't have quotes though with quotes the script doesn't work. I'm totally baffled and simply can't find anything, suggestions please?

- John

function smiley_convert(text)
{
if (document.getElementsByTagName('*').length!=0)
{
var smileyTranslator = {
'0:)' : 'angel',
':d' : 'big-grin',
':b' : 'blush',
'?(' : 'confused',
'c(' : 'crying',
'o.0' : 'disbelief',
':>' : 'dork',
'>)' : 'evil-grin',
':p' : 'glee',
':)' : 'happy',
':|' : 'indifferent',
'8)' : 'joe-cool',
':lol' : 'laugh',
':l' : 'love',
':n' : 'nervous',
'n)' : 'nut',
'>__>' : 'paranoid',
':r' : 'reading',
':s' : 'spitting',
'o.o' : 'surprised',
'<.<^' : 'uncertain',
'-__-' : 'unimpressed',
'>:<' : 'vampire',
';)' : 'wink'
};
var converted = text.replace(/0:\)|:d|:b|\?\(|c\(|o.0|:\>|\>\)|:p|:\)|:\||8\)|:lol|:l|:n|n\)|>__>|:r|:s|o.o|<.<\^|-__-|>:<|;\)/g,function (s) {if (s in smileyTranslator) {return '[img]'+path+'images/smiley_'+ smileyTranslator[s] +'.gif[/img]';} return s;});
}
else
{
var converted = ' ';
}
return converted;
}
6:23 pm on Nov 1, 2010 (gmt 0)

WebmasterWorld Senior Member fotiman is a WebmasterWorld Top Contributor of All Time 5+ Year Member Top Contributors Of The Month



Does it work for any other browsers? Your replace seems to be malformed. It's supposed to take 2 parameters, the regexp/substring to replace and the new string to replace it with. However, I see a function where the new string is supposed to be.
3:26 am on Nov 4, 2010 (gmt 0)

WebmasterWorld Senior Member jab_creations is a WebmasterWorld Top Contributor of All Time 10+ Year Member



Actually I had help here over in the JavaScript forums with this script and I think I've seen you mod over in the JavaScript forums before. ;)

- John
1:28 pm on Nov 4, 2010 (gmt 0)

WebmasterWorld Senior Member fotiman is a WebmasterWorld Top Contributor of All Time 5+ Year Member Top Contributors Of The Month



Ok, I must have missed that thread. Glad you got it working. :)
3:36 am on Nov 5, 2010 (gmt 0)

WebmasterWorld Senior Member jab_creations is a WebmasterWorld Top Contributor of All Time 10+ Year Member



Thanks Fotiman, though do you have any recommendations on what I could try to get Opera 9 to handle this correctly? Is it a known bug or something?

- John
2:47 pm on Nov 5, 2010 (gmt 0)

WebmasterWorld Senior Member fotiman is a WebmasterWorld Top Contributor of All Time 5+ Year Member Top Contributors Of The Month



As I said above, your "replace" seems to be malformed. It's supposed to take 2 parameters, the regexp/substring to replace and the new string to replace it with. However, I see a function where the new string is supposed to be.
 

Featured Threads

Hot Threads This Week

Hot Threads This Month