andleer
andleer

Reputation: 22568

Encode TextArea for GET request

I need to pass the contents of a textarea as the source attribute of an image tag and capture all input including line breaks etc.

It looks like the only way to do this is to base 64 encode it and then urlEncode the result. (I can then unencode it all server side.)

  1. Is that correct?
  2. Is there a preferred base 64 library for javascript? must be cross browser.

Upvotes: 0

Views: 1565

Answers (2)

Quentin
Quentin

Reputation: 943213

It looks like the only way to do this is to base 64 encode it and then urlEncode the result. (I can then unencode it all server side.)

You only need to base64 encode binary data - which a textarea won't contain.

Just use encodeURIComponent

Upvotes: 3

Mario
Mario

Reputation: 36487

urlEncode should be enough (no need for base64 as you could express line breaks as (e.g.) %0D%0A as well) but whatever you're building sounds quite vulnerable to cross site scripting exploits.

Upvotes: 0

Related Questions