Escaping

gav on 2004-04-09T15:03:27

The Web Standards Project likes a little bit of Perl I wrote.


the script

Juerd on 2004-04-09T20:13:00

A classic example of weird editor settings. Unless of course that is your favourite indenting style.

Anyway, I think encode_url is a bad name for a function that does not URL-encode (i.e. the %-thing). It does not even have anything to do with URLs. In fact, I would not have used a separate sub for it.

But, as always, it works and it serves a purpose. As does most software.

Re:the script

gav on 2004-04-09T21:04:10

It just needed a %retab. Looks much neater now, darn tabs.

The reason it's called encode_url is because it encodes the entities in a url. If it was going to do the %-thing, it would be escaping (using URI::Escape). At least that's how I distinguish between the two things, I could be wrong.

Re:the script

Juerd on 2004-04-09T21:34:44

RFC 2396 calls it "Escaped Encoding" (2.4.1).

Which means some people call it escaping, some call it encoding. Perlfaq9 calls it encoding, URI::Escape calls it escaping.

The thing is exactly the same with HTML Entities: it is escaping AND encoding. Encoding because it changes in a way that can be reversed, escaped because most text is as it is and an escape character (% in a URI, & in HTML) is used to introduce an encoded octet/character..

I'd expect a sub called encode_url to URI-encode because of the "url" in the name. I would have called this sub "reencode_entities" because all it does is "encode_entities(decode_entities($foo))". It is not URL-specific so "url" should not be in the name.