code_junkie

Allowing dangerous query strings

Nov 12th, 2011
52
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.42 KB | None | 0 0
  1. System.Text.ASCIIEncoding.ASCII.GetBytes
  2.  
  3. System.Convert.ToBase64String
  4.  
  5. System.Convert.FromBase64String
  6.  
  7. System.Text.ASCIIEncoding.ASCII.GetString
  8.  
  9. $(document).ready( function() {
  10. $('form').bind('submit', function() {
  11. $('form' > 'input[type=text]').each( function(i) {
  12. if (this.value) {
  13. this.value = encode(this.value);
  14. }
  15. });
  16. });
  17. });
  18.  
  19. function encode(value) {
  20. return ...suitable encoding...
  21. }
  22.  
  23. <script type="text/javascript">
  24.  
  25. var unencodedText = "This is my text that contains whitespaces and characters like and Ø";
  26. var encodedText = "";
  27. var decodedText = "";
  28. alert('unencodedText: ' + unencodedText);
  29.  
  30. //To encode whitespaces and the 'Ø' character - use encodeURI
  31. encodedText = encodeURI(unencodedText);
  32. //We see that whitespaces and 'Ø' are encoded, but the '' is still there:
  33. alert('encodedText: ' + encodedText);
  34.  
  35. //If we decode it we should get our unencodedText back
  36. decodedText = decodeURI(encodedText);
  37. alert('decodedText: ' + decodedText);
  38.  
  39. //To also encode the '' we use the encodeURIComponent
  40. encodedText = encodeURIComponent(unencodedText);
  41. //Now all the characters have been encoded:
  42. alert('encodedText: ' + encodedText);
  43.  
  44. //To get our unencodedText back we now need to use the decodeURIComponent
  45. decodedText = decodeURIComponent(encodedText);
  46. alert('decodedText: ' + decodedText);
  47.  
  48. </script>
Add Comment
Please, Sign In to add comment