Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > ASP .Net > ASP General > Response.Write double quotes in JScript

Reply
Thread Tools

Response.Write double quotes in JScript

 
 
Jon Maz
Guest
Posts: n/a
 
      07-08-2004
Hi,

I have written a page to test a function of mine that strips non-English
accents and various other characters out of a given string. The function
itself (called 'StripAll' in the code below) now works fine.

However something else in the test page is not working, and it's starting to
bug me! If the user types a string containing double quotes into the
textbox, when the textbox is re-populated after the postback, any part of
the entered string *after* the first double quote is lost.

I'm wondering what I'm doing wrong here. It's just a minor point, but it's
getting annoying!

Any help appreciated,

TIA,

JON

PS The issue is presumably the RegExp in function
EscapeDoubleInvertedCommas.



------------------------------------------


<%@ LANGUAGE="JavaScript"%>


<%
var sourceString = "" + Request.Form("txtSourceString");
var defaultSourceString = "
Y &&&123~~~~45";

function RemoveDoubleInvertedCommas(sourceString)
{
re = new RegExp(("\""), "g");
return sourceString.replace(re, "\"");
}

function EscapeDoubleInvertedCommas(sourceString)
{
//trying to refill the textbox on postback with any inverted commas that
were typed in!
//NOT WORKING!
re = new RegExp(("\""), "g");
return sourceString.replace(re, "\"\"");
}
%>




<form method="post" id="form1" name="form1">

URL: <input name="txtSourceString" type="text" value="<% if (sourceString
!= "undefined") {Response.Write(EscapeDoubleInvertedCommas(sourceS tring))}
else {Response.Write(defaultSourceString)}%>" id="txtSourceString"
style="width:500px;" />
<br>
<input type="submit" name="btnTest" value="Test StripAll" id="btnTest" />
<br>

<hr>

Stripped version: <% if(sourceString != "undefined")
{Response.Write(StripAll(RemoveDoubleInvertedComma s(sourceString)));}%>
<br>


</form>


<%

function StripAccents(sourceString)
{
re = new RegExp("|||||", "g");
sourceString = sourceString.replace(re, "a");

re = new RegExp("|||||", "g");
sourceString = sourceString.replace(re, "A");

re = new RegExp((""), "g");
sourceString = sourceString.replace(re, "c");

re = new RegExp((""), "g");
sourceString = sourceString.replace(re, "C");

re = new RegExp(("|||||"), "g");
sourceString = sourceString.replace(re, "e");

re = new RegExp(("|||||"), "g");
sourceString = sourceString.replace(re, "E");

re = new RegExp(("|||"), "g");
sourceString = sourceString.replace(re, "i");

re = new RegExp(("|||"), "g");
sourceString = sourceString.replace(re, "I");

re = new RegExp((""), "g");
sourceString = sourceString.replace(re, "n");

re = new RegExp((""), "g");
sourceString = sourceString.replace(re, "N");

re = new RegExp(("|||||"), "g");
sourceString = sourceString.replace(re, "o");

re = new RegExp(("|||||"), "g");
sourceString = sourceString.replace(re, "O");

re = new RegExp("", "g");
sourceString = sourceString.replace(re, "ss");

re = new RegExp(("|||"), "g");
sourceString = sourceString.replace(re, "u");

re = new RegExp(("|||"), "g");
sourceString = sourceString.replace(re, "U");

re = new RegExp(("|"), "g");
sourceString = sourceString.replace(re, "y");

re = new RegExp(("|Y"), "g");
sourceString = sourceString.replace(re, "Y");

return sourceString;
}

function StripAll(sourceString)
{
sourceString = StripAccents(sourceString);

re = new RegExp((" "), "g");
sourceString = sourceString.replace(re, "");

re = new RegExp(("_"), "g");
sourceString = sourceString.replace(re, "");

re = new RegExp(("&"), "g");
sourceString = sourceString.replace(re, "");

re = new RegExp(("~"), "g");
sourceString = sourceString.replace(re, "");

re = new RegExp(("'|;|:"), "g");
sourceString = sourceString.replace(re, "");

re = new RegExp(("\""), "g");
sourceString = sourceString.replace(re, "");

return sourceString;
}

%>



 
Reply With Quote
 
 
 
 
Ray at
Guest
Posts: n/a
 
      07-08-2004
Server.HTMLEncode the value. The problems is that you're ending up with
something like:

<input type="text" name="something" value="He said, "Hi how are you?"">

The browser will see the " before Hi and assume it is the end of the value.
By Server.HTMLEncoding it, you'll get:

<input type="text" name="something" value="He said, &quot;Hi how are
you?&quot;">

Ray at work

"Jon Maz" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
> Hi,
>
> I have written a page to test a function of mine that strips non-English
> accents and various other characters out of a given string. The function
> itself (called 'StripAll' in the code below) now works fine.
>
> However something else in the test page is not working, and it's starting
> to
> bug me! If the user types a string containing double quotes into the
> textbox, when the textbox is re-populated after the postback, any part of
> the entered string *after* the first double quote is lost.
>
> I'm wondering what I'm doing wrong here. It's just a minor point, but
> it's
> getting annoying!
>
> Any help appreciated,
>
> TIA,
>
> JON
>
> PS The issue is presumably the RegExp in function
> EscapeDoubleInvertedCommas.
>
>
>
> ------------------------------------------
>
>
> <%@ LANGUAGE="JavaScript"%>
>
>
> <%
> var sourceString = "" + Request.Form("txtSourceString");
> var defaultSourceString = "
> Y &&&123~~~~45";
>
> function RemoveDoubleInvertedCommas(sourceString)
> {
> re = new RegExp(("\""), "g");
> return sourceString.replace(re, "\"");
> }
>
> function EscapeDoubleInvertedCommas(sourceString)
> {
> //trying to refill the textbox on postback with any inverted commas that
> were typed in!
> //NOT WORKING!
> re = new RegExp(("\""), "g");
> return sourceString.replace(re, "\"\"");
> }
> %>
>
>
>
>
> <form method="post" id="form1" name="form1">
>
> URL: <input name="txtSourceString" type="text" value="<% if (sourceString
> != "undefined") {Response.Write(EscapeDoubleInvertedCommas(sourceS tring))}
> else {Response.Write(defaultSourceString)}%>" id="txtSourceString"
> style="width:500px;" />
> <br>
> <input type="submit" name="btnTest" value="Test StripAll" id="btnTest" />
> <br>
>
> <hr>
>
> Stripped version: <% if(sourceString != "undefined")
> {Response.Write(StripAll(RemoveDoubleInvertedComma s(sourceString)));}%>
> <br>
>
>
> </form>
>
>
> <%
>
> function StripAccents(sourceString)
> {
> re = new RegExp("|||||", "g");
> sourceString = sourceString.replace(re, "a");
>
> re = new RegExp("|||||", "g");
> sourceString = sourceString.replace(re, "A");
>
> re = new RegExp((""), "g");
> sourceString = sourceString.replace(re, "c");
>
> re = new RegExp((""), "g");
> sourceString = sourceString.replace(re, "C");
>
> re = new RegExp(("|||||"), "g");
> sourceString = sourceString.replace(re, "e");
>
> re = new RegExp(("|||||"), "g");
> sourceString = sourceString.replace(re, "E");
>
> re = new RegExp(("|||"), "g");
> sourceString = sourceString.replace(re, "i");
>
> re = new RegExp(("|||"), "g");
> sourceString = sourceString.replace(re, "I");
>
> re = new RegExp((""), "g");
> sourceString = sourceString.replace(re, "n");
>
> re = new RegExp((""), "g");
> sourceString = sourceString.replace(re, "N");
>
> re = new RegExp(("|||||"), "g");
> sourceString = sourceString.replace(re, "o");
>
> re = new RegExp(("|||||"), "g");
> sourceString = sourceString.replace(re, "O");
>
> re = new RegExp("", "g");
> sourceString = sourceString.replace(re, "ss");
>
> re = new RegExp(("|||"), "g");
> sourceString = sourceString.replace(re, "u");
>
> re = new RegExp(("|||"), "g");
> sourceString = sourceString.replace(re, "U");
>
> re = new RegExp(("|"), "g");
> sourceString = sourceString.replace(re, "y");
>
> re = new RegExp(("|Y"), "g");
> sourceString = sourceString.replace(re, "Y");
>
> return sourceString;
> }
>
> function StripAll(sourceString)
> {
> sourceString = StripAccents(sourceString);
>
> re = new RegExp((" "), "g");
> sourceString = sourceString.replace(re, "");
>
> re = new RegExp(("_"), "g");
> sourceString = sourceString.replace(re, "");
>
> re = new RegExp(("&"), "g");
> sourceString = sourceString.replace(re, "");
>
> re = new RegExp(("~"), "g");
> sourceString = sourceString.replace(re, "");
>
> re = new RegExp(("'|;|:"), "g");
> sourceString = sourceString.replace(re, "");
>
> re = new RegExp(("\""), "g");
> sourceString = sourceString.replace(re, "");
>
> return sourceString;
> }
>
> %>
>
>
>



 
Reply With Quote
 
 
 
 
Jon Maz
Guest
Posts: n/a
 
      07-08-2004
Bingo! Nice one Ray!



JON


 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
regex to avoid escaped quotes or double quotes jOhn Ruby 1 01-29-2008 08:31 PM
PHP double quotes inside double quotes MSB Computer Support 11 10-21-2006 01:09 PM
cannot convert parameter from 'double (double)' to 'double (__cdecl *)(double)' error Sydex C++ 12 02-17-2005 06:30 PM
Quotes/Double Quotes in Image Control Chris White ASP .Net 1 09-22-2004 06:22 AM
Porting from JScript to JScript.Net - compiler error Jon Maz ASP .Net 4 09-09-2004 10:24 AM



Advertisments