Encoding nightmare

C

comopasta Gr

Hi,

I working on an application that is localized in several languages and
I'm facing some problems with special characters.

I have a name field that can take inputs such as:

Validaci=C3=B3n
Tom's card

So those two string above contain ' and =C2=B4 spcecial characters.

In the application I need to feed those to a javascript function using
onclick, so I use:

onclick=3D"remove('<%=3D card.name %>')"

Doing it that way, the HTML results in:

onclick=3D"remove('Validaci=C3=B3n')"
onclick=3D"remove('Tom's card')"

You can see that the first one is ok, but the second on is not because
of the ' in between the m and the s which causes the javascript
to fail.

To avoid that I can use:

onclick=3D"remove('<%=3D CGI::escape(tag.name) %>')"

And that results in:

onclick=3D"remove('Tom%27s+card')"
onclick=3D"remove('Validaci%C3%B3n')"

The name in the remove function is used to show a confimation so I have
show the name back to the user.

So I use javascript method unescape(card_name.replace(/\+/g, " ")) to
convert the %27 and + back to ' and space to show the original. And that
goes ok.

BUT now the other one is converted to Validaci=C3=83=C2=B3n
Note the =C3=83=C2=B3

-----

I can't find a way to fix one without breaking the other.
Any suggestions to solve this problem?

Cheers.

-- =

Posted via http://www.ruby-forum.com/.=
 
J

Josef 'Jupp' Schugt

onclick=3D"remove('Tom%27s+card')"
onclick=3D"remove('Validaci%C3%B3n')" :
BUT now the other one is converted to Validaci=C3=83=C2=B3n
Note the =C3=83=C2=B3

There is two parts to this. Firstly you are using Percent-encoding (aka =
=

URL encoding) which maps spaces to plus signs and characters to %XY toke=
ns =

wiht X and Y being a hexadecimal digit. This works as intended. Secondly=
=

you are encoding the characters according to utf-8 which maps "'" to %27=
=

and "=C3=B3" to %C3%B3. However, for displaying ISO-8859-15, Windows-125=
2 (aka =

CP 1252) is used which interprets %C3 as =C3=82 and %B3 as =C2=B3.

Try either switching to utf-8 or - if this is not possible - using %F3 a=
s =

the proper encoding of "=C3=B3" for the given character set.

Jupp
 
Y

Y. NOBUOKA

Hi,
So those two string above contain ' and =B4 spcecial characters.

In the application I need to feed those to a javascript function using
onclick, so I use:

onclick=3D"remove('<%=3D card.name %>')"

Doing it that way, the HTML results in:

onclick=3D"remove('Validaci=F3n')"
onclick=3D"remove('Tom's card')"

You can see that the first one is ok, but the second on is not because
of the ' in between the m and the s which causes the javascript
to fail.

One way to avoiding this is escaping the apostrophe character (') by using
a backslash character (\).

Please try following code:
onclick=3D"remove('<%=3D card.name.gsub( "'" ){ "\\'" } %>')"

--=20
NOBUOKA Yu
 
Y

Y. NOBUOKA

Sorry, there is a mistake.

incorrect : require 'ERB'
correct : require 'erb'
 
C

comopasta Gr

Y. NOBUOKA wrote in post #996593:
Hi,


One way to avoiding this is escaping the apostrophe character (') by
using
a backslash character (\).

Please try following code:
onclick="remove('<%= card.name.gsub( "'" ){ "\\'" } %>')"

That I've done and it goes ok without disturbing the accents in spanish.

Thanks a lot.
 
C

comopasta Gr

Josef 'Jupp' Schugt wrote in post #996590:
There is two parts to this. Firstly you are using Percent-encoding (aka=
URL encoding) which maps spaces to plus signs and characters to %XY
tokens
wiht X and Y being a hexadecimal digit. This works as intended. Secondl= y
you are encoding the characters according to utf-8 which maps "'" to %2= 7
and "=C3=B3" to %C3%B3. However, for displaying ISO-8859-15, Windows-12= 52
(aka
CP 1252) is used which interprets %C3 as =C3=82 and %B3 as =C2=B3.

Try either switching to utf-8 or - if this is not possible - using %F3
as
the proper encoding of "=C3=B3" for the given character set.

Jupp

Hi, thanks for the tip. As replied earlier I managed to solve the issue =

with gsub. I just wanted to comment that utf-8 should be in use already. =

At least based on the meta info generated:

<meta http-equiv=3D"Content-Type" content=3D"text/html; charset=3DUTF-8">=


Thanks again.

-- =

Posted via http://www.ruby-forum.com/.=
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,579
Members
45,053
Latest member
BrodieSola

Latest Threads

Top