473,396 Members | 2,068 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

Quotes issue...

I think it's a common problem, but I haven't found answers for it.
I have a sentence (mixture of HTML, Javascript and JSTL) like this:

<a href='javascript:selectItem('${item.code}', '${item.alias}');
${item.alias}
</a>

${item.alias} is a JSTL way to get a String from a parameter
that may contains single or double quotes.

If the string contains single quotes I get an error because the
sentence is not well formed. But if I use double quotes and the
string have double quotes I'll get the same error.

What is the way to solve this issue? Is there any?
Jul 23 '05 #1
3 5547
EdUarDo wrote:
I think it's a common problem, but I haven't found answers for it.
I have a sentence (mixture of HTML, Javascript and JSTL) like this:

<a href='javascript:selectItem('${item.code}', '${item.alias}');
${item.alias}
</a>

${item.alias} is a JSTL way to get a String from a parameter
that may contains single or double quotes.

If the string contains single quotes I get an error because the
sentence is not well formed. But if I use double quotes and the
string have double quotes I'll get the same error.

What is the way to solve this issue? Is there any?


As a guess (I can't test it right now), replace any double
quotes in "item.alias" with "%22" and single quotes with "%27".

The in your javascript, unescape the strings before you use
them. The following shows the principle (the encoding will
occur on your server I guess?):

<form action="">
<input type="text" value="'" name="txt"><br>
<input type="button" value="encode" onclick="
this.form.code.value = escape(this.form.txt.value);
"><br>
<input type="text" name="code"><br>
<input type="button" value="decode" onclick="
alert(unescape(this.form.code.value));
">
<input type="reset">
</form>

--
Rob
Jul 23 '05 #2
As a guess (I can't test it right now), replace any double
quotes in "item.alias" with "%22" and single quotes with "%27".

The in your javascript, unescape the strings before you use
them. The following shows the principle (the encoding will
occur on your server I guess?):


This doesn't work for me.
At server I've replaced all single and double quotes with %27 and %22
respectively.

And my client page have this code:

<tr>
<td align="left">
<a href="javascript:
selectItem('${item.code}', '${item.alias}', '${item.descriptions[SPANISH]}', '${item.descriptions[ENGLISH]}');">
${item.alias}
</a>
</td>
<td align="center">${item.code}</td>
<td align="center">${item.descriptions[SPANISH]}</td>
<td align="center">${item.descriptions[ENGLISH]}</td>
<td align="left">${item.tableName}</td>
</tr>

Once it's processed, the resulting code is:

<tr>
<td align="left">
<a href="javascript:selectItem('1440000002', '03', 'elemento%27uno', 'elemento%27uno');">
03
</a>
</td>
<td align="center">1440000002</td>
<td align="center">elemento%27uno</td>
<td align="center">elemento%27uno</td>
<td align="left">tabla1</td>
</tr>

When I click on the link (a href) I get this error

Error: missing ) after argument list
Source File: javascript:selectItem('1440000002', '03', 'elemento%27uno', 'elemento%27uno');
Line: 1, Column: 50
Source Code:
selectItem('1440000002', '03', 'elemento'uno', 'elemento'uno');
------------------------------------------^

Also I have tried to unescape the descriptions but with the same results.

Jul 23 '05 #3
EdUarDo wrote:
As a guess (I can't test it right now), replace any double
quotes in "item.alias" with "%22" and single quotes with "%27".

The in your javascript, unescape the strings before you use
them. The following shows the principle (the encoding will
occur on your server I guess?):


This doesn't work for me.
At server I've replaced all single and double
quotes with %27 and %22 respectively.

<snip>

It wouldn't, that is URL encoding. For javascript you want to use
javascript escape sequences within strings. Escape sequences begin with
a backslash followed with an 'x' then a two digit hexadecimal number
(the character code in hex) or with a 'u' followed by the four digit
hexadecimal Unicode character code. I don't have time to look up the
values for quote characters but they should be easy to work out form the
ECMA Script language specification (or any decent javascript reference)
(but I would guess (hex) - \x27 - and - \x22 -, or (Unicode) - \u0027 -
and \u2200 - if the URL encoding is correct).

Richard.
Jul 23 '05 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

13
by: lawrence | last post by:
A user writes this sentence: "It was the New Urbanist's nightmare of sprawl run amok." They input that and my PHP script hits it with addslashes() and then the sentence gets put in the database....
12
by: Brett Hofer | last post by:
I must be missing something - Im a veteran C++ programmer now working with C# overall I like the language but find many weird changes... Anyway Im writing code behind an aspx. In this one C#...
7
by: Tim Mulholland | last post by:
I have an issue i can work around, but i'm trying to figure out what i'm "supposed" to do. i have a line of HTML/ASP.NET code inside a repeater that is something like this <a...
6
by: SStory | last post by:
How can I handle the user entering single quotes like in Bob's mini mart? If I use command objects will this no longer be an issue? I guess that would mean no simple adhoc SQL statements...
37
by: Ian Rastall | last post by:
I've been working on an online books site for almost four years now, and have been putting smart quotes in each book. This is a major hassle, and I'm beginning to think it's not worth it. Is...
3
by: apiringmvp | last post by:
All, So I am creating a function that gets a short blurb of html from a blog. I would like to retain all html formating and images. The code below works well, with the exception of one issue....
8
by: Bill Gower | last post by:
I want to store an SQL string into a table and then be able to run it later. Here is the insert command "insert into ProjectSQL(ProjectID, SQLID, SQLString) values( " & locProjectID & ", " &...
15
by: bill | last post by:
I am trying to write clean code but keep having trouble deciding when to quote an array index and when not to. sometimes when I quote an array index inside of double quotes I get an error about...
1
by: Yearwood | last post by:
Hi, I'm basically trying to import a CSV into an ACCESS database. Sample date is shown below: "",10173,"Development Manager - Social Economy Sector","Trust Bank",10153,,"Lolalll Pudd","Meet the...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.