Skip to search.

Breaking News Visit Yahoo! News for the latest.

×Close this window

jslint_com · This group has moved to Google Plus.

The Yahoo! Groups Product Blog

Check it out!

Group Information

  • Members: 584
  • Category: JavaScript
  • Founded: Mar 7, 2008
  • Language: English
? Already a member? Sign in to Yahoo!

Yahoo! Groups Tips

Did you know...
Hear how Yahoo! Groups has changed the lives of others. Take me there.

Messages

Advanced
Messages Help
Bad escapement.   Topic List   < Prev Topic  |  Next Topic >
Summarize Messages | View Threaded Sort by Date v  
#1589 From: "pauanyu" <pcxunlimited@...>
Date: Sat Nov 13, 2010 3:48 pm
Subject: [jslint] Re: Bad escapement.
pauanyu
Send Email Send Email
 
--- In jslint_com@yahoogroups.com, "Cheney, Edward A SSG RES USAR USARC"
<austin.cheney@...> wrote:
>
>
> > Try this regular expression:
> >
> > /url\(((?:[^\)\\]|\\.)*)\)/
> >
> > You would use it like so:
> >
> > string.replace(regexp, "url(\"$1\")");
> >
>
> There are some problems with that.
>
> 1) The regexp does not account for the prior existence of single or double
quote characters that may or may not be applied in a valid manner.

Correct. I attempted to do that with a regular expression, and I'm not sure if
it's even possible. Additional logic will likely be required to check for
already-existing quotes.

> 2) The regexp does not appear to be accounting for open parenthesis with or
without proper escapement.

With the above regular expression, the following would match:

url(foo(bar)

url(foo\(bar)

It could probably be changed to make the above invalid.

> 3) There are many characters that have valid syntax representation in URI and
like wise have valid syntax representation in CSS. These characters have to be
accounted for in a manner that is not conflicting with CSS syntax and
simultaneously does not alter their application in a URI instance.

The above expression matches any character except a non-escaped ). That means,
that it is extremely liberal in what it accepts. If you want it to be stricter,
that would be possible as well, though it would require more work. Thus, this is
valid (as it should be):

url(ftp://www.foo.com/search?bar=%F0%9D%95%A2%F0%9D%95%A6%F0%9D%95%A9#%E2%81%98)

> As a result I have chosen to use regexp to escape certain necessary characters
into an arbitrary string and perform the next stages of processing using
standard string methods in a loop.

That is fine, just be careful because it is possible (albeit very unlikely) for
your arbitrary string to be found in the URI.




#1588 From: "Cheney, Edward A SSG RES USAR USARC" <austin.cheney@...>
Date: Thu Nov 11, 2010 10:35 pm
Subject: Re: [jslint] Re: Bad escapement.
sandyhead25
Send Email Send Email
 

> Try this regular expression:
>
> /url\(((?:[^\)\\]|\\.)*)\)/
>
> You would use it like so:
>
> string.replace(regexp, "url(\"$1\")");
>

There are some problems with that.

1) The regexp does not account for the prior existence of single or double quote
characters that may or may not be applied in a valid manner.
2) The regexp does not appear to be accounting for open parenthesis with or
without proper escapement.
3) There are many characters that have valid syntax representation in URI and
like wise have valid syntax representation in CSS. These characters have to be
accounted for in a manner that is not conflicting with CSS syntax and
simultaneously does not alter their application in a URI instance.

Regular expression execution is supposed to be one of the fastest forms of
execution in JavaScript against large string blocks because the execution is
performed below the JavaScript interpretation. However, I have found that
regexp execution is only fast when it is performed outside of any loop
conditions. When regexp execution is performed inside a loop then you suffer
dire consequences since the interpreter must fire on each loop index and halts
each time for return of independently executed regexp. The complexity of the
regexp also plays a very big part in this lag as well. This said if any logic
has to be applied to a regexp match where that logic requires any sort of
looping or if a regexp executes only in response to conditions in a loop then it
is best to not use regexp at all and just use standard string methods in normal
JavaScript loops. As a result I have chosen to use regexp to escape certain
necessary characters into an arbitrary string and perform the next stages of
processing using standard string methods in a loop. Another alternative is
nested regexp execution where a replace method searches for a match and the
replacement value fires a function that executes another regexp instruction, but
this method is less flexible and opens complexity to the depth of known test
cases.



#1587 From: "pauanyu" <pcxunlimited@...>
Date: Thu Nov 11, 2010 5:54 pm
Subject: Re: Bad escapement.
pauanyu
Send Email Send Email
 
Try this regular expression:

/url\(((?:[^\)\\]|\\.)*)\)/

You would use it like so:

string.replace(regexp, "url(\"$1\")");


--- In jslint_com@yahoogroups.com, "Cheney, Edward A SSG RES USAR USARC"
<austin.cheney@...> wrote:
>
> Using JavaScript I am attempting to forcefully inject double quote characters
into the parentheses of url fragments in CSS, so that url(jslint.com) becomes
url("jslint.com"). To keep from breaking complex URIs I am replacing
parenthesis characters that are escaped with a forward slash with an arbitrary
string:
>
> y = y.replace(/\\\)/g, "~PDpar~");
>
> When I am done with my function I need to return the escaped parentheses back
into the code, so logically I am using:
>
> y = y.replace(/~PDpar~/g, "\\\)");
>
> JSLint throws an error when "\)" is present in the second argument of a
replace method. Is there a string equivalent that can be used which will not
throw a fit? I understand I could simply throw a function in there which
returns a static string to prevent JSLint from directly associating the
problematic string with the replacement method, but arbitrary function calls is
less efficient for the interpreter.
>
> Thanks,
>
> Austin Cheney, CISSP
> http://prettydiff.com/
>





#1578 From: Harry Whitfield <g7awz@...>
Date: Fri Nov 5, 2010 2:30 pm
Subject: Re: [jslint] Bad escapement.
harry152566
Send Email Send Email
 

On 5 Nov 2010, at 14:12:22, Cheney, Edward A SSG RES USAR USARC wrote:

> Using JavaScript I am attempting to forcefully inject double quote characters
into the parentheses of url fragments in CSS, so that url(jslint.com) becomes
url("jslint.com"). To keep from breaking complex URIs I am replacing parenthesis
characters that are escaped with a forward slash with an arbitrary string:
>
> y = y.replace(/\\\)/g, "~PDpar~");
>
> When I am done with my function I need to return the escaped parentheses back
into the code, so logically I am using:
>
> y = y.replace(/~PDpar~/g, "\\\)");
>
> JSLint throws an error when "\)" is present in the second argument of a
replace method. Is there a string equivalent that can be used which will not
throw a fit? I understand I could simply throw a function in there which returns
a static string to prevent JSLint from directly associating the problematic
string with the replacement method, but arbitrary function calls is less
efficient for the interpreter.

var y = "\\)abc\\)fgh";
print(y);
y = y.replace(/\\\)/g, "~PDpar~");
print(y);
y = y.replace(/~PDpar~/g, "\\)"); // leave out the third backslash
print(y);

Output is:

\)abc\)fgh
~PDpar~abc~PDpar~fgh
\)abc\)fgh

Harry.




#1577 From: "Cheney, Edward A SSG RES USAR USARC" <austin.cheney@...>
Date: Fri Nov 5, 2010 2:12 pm
Subject: Bad escapement.
sandyhead25
Send Email Send Email
 
Using JavaScript I am attempting to forcefully inject double quote characters
into the parentheses of url fragments in CSS, so that url(jslint.com) becomes
url("jslint.com"). To keep from breaking complex URIs I am replacing
parenthesis characters that are escaped with a forward slash with an arbitrary
string:

y = y.replace(/\\\)/g, "~PDpar~");

When I am done with my function I need to return the escaped parentheses back
into the code, so logically I am using:

y = y.replace(/~PDpar~/g, "\\\)");

JSLint throws an error when "\)" is present in the second argument of a replace
method. Is there a string equivalent that can be used which will not throw a
fit? I understand I could simply throw a function in there which returns a
static string to prevent JSLint from directly associating the problematic string
with the replacement method, but arbitrary function calls is less efficient for
the interpreter.

Thanks,

Austin Cheney, CISSP
http://prettydiff.com/



 
Add to My Yahoo!      XML What's This?

Copyright © 2010 Yahoo! Inc. All rights reserved.
Privacy Policy - Terms of Service - Guidelines NEW - Help