[Project_owners] &amp and &regl in links/uri's

Michael Johnston special.michael at gmail.com
Tue Sep 6 21:05:36 EDT 2005


text = "foo=bar&bar=baz";
>> text = text.replace( /&/g, "&" );
>
double sweep?
ie take a second regexp with 

text="../somepage.html?id=foo&amp;number<wbr>=somenumber"
text = text.replace( /&/g, "&amp;" );
text = text.replace( /&amp;amp;/g, "&amp;" );

worse performace.

On 9/6/05, Claus Augusti <caugusti at formatvorlage.de> wrote:
> Hi Michael,
> 
> Michael Vincent wrote:
> 
> > Claus Augusti wrote:
> >
> >> Hi Michael,
> >>
> >> your question isn't really clear... what exactly are you trying to do?
> >
> >
> > I read some remote XML files and some of them are invalid XML (because
> > they use & instead of &amp; for example) but that should not break my
> > code ;)
> >
> >> You can use the &amp; inside HTML links, as it's replaced by & during
> >> parsing, so you can use both to separate key/value pairs inside the
> >> query string. In XHTML/XML you have to use the entity version anyways.
> >>
> >> If you want to send an ampersand as part of a key's value and not to
> >> separate key/value pairs, you need to do URI encoding, which is done by
> >>
> >> escape("Barnes&Noble")
> >> or
> >> escapeURIComponent("Barnes&Noble"), which is the Unicode-safe version.
> >
> >
> > Can that be used in a web based application (I don't have access to a
> > chrome window, as far as I know).
> 
> Yes, both these functions are part of JavaScript itself.
> 
> >
> >> However, the regex to replace & by &amp; is:
> >>
> >> text = "foo=bar&bar=baz";
> >> text = text.replace( /&/g, "&amp;" );
> >
> >
> > Yes, but that breaks for uri's like this:
> >
> > ../somepage.html?id=foo&number=somenumber
> 
> I don't understand... you mean you need to distinguish between &s used
> as uri parameter separator and &s used inside of values?
> 
> >
> > That is what I like to solve...if possible
> >
> > Thanks,
> > Michael
> > _______________________________________________
> > Project_owners mailing list
> > Project_owners at mozdev.org
> > http://mozdev.org/mailman/listinfo/project_owners
> 
> 
> _______________________________________________
> Project_owners mailing list
> Project_owners at mozdev.org
> http://mozdev.org/mailman/listinfo/project_owners
>


More information about the Project_owners mailing list