| line | stmt | bran | cond | sub | pod | time | code | 
| 1 |  |  |  |  |  |  | # -*- perl -*- | 
| 2 |  |  |  |  |  |  |  | 
| 3 |  |  |  |  |  |  | # | 
| 4 |  |  |  |  |  |  | # $Id: Escape.pm,v 1.2 2004/12/13 23:19:39 eserte Exp $ | 
| 5 |  |  |  |  |  |  | # Author: Slaven Rezic | 
| 6 |  |  |  |  |  |  | # | 
| 7 |  |  |  |  |  |  | # Copyright (C) 2004 Slaven Rezic. All rights reserved. | 
| 8 |  |  |  |  |  |  | # This package is free software; you can redistribute it and/or | 
| 9 |  |  |  |  |  |  | # modify it under the same terms as Perl itself. | 
| 10 |  |  |  |  |  |  | # | 
| 11 |  |  |  |  |  |  | # Mail: eserte@users.sourceforge.net | 
| 12 |  |  |  |  |  |  | # WWW:  http://www.sf.net/projects/we-framework/ | 
| 13 |  |  |  |  |  |  | # | 
| 14 |  |  |  |  |  |  |  | 
| 15 |  |  |  |  |  |  | package WE::Util::Escape; | 
| 16 |  |  |  |  |  |  |  | 
| 17 | 1 |  |  | 1 |  | 979 | use strict; | 
|  | 1 |  |  |  |  | 2 |  | 
|  | 1 |  |  |  |  | 29 |  | 
| 18 | 1 |  |  | 1 |  | 4 | use vars qw($VERSION); | 
|  | 1 |  |  |  |  | 1 |  | 
|  | 1 |  |  |  |  | 62 |  | 
| 19 |  |  |  |  |  |  | $VERSION = sprintf("%d.%02d", q$Revision: 1.2 $ =~ /(\d+)\.(\d+)/); | 
| 20 |  |  |  |  |  |  |  | 
| 21 | 1 |  |  | 1 |  | 5 | use vars qw(%uri_escapes); | 
|  | 1 |  |  |  |  | 1 |  | 
|  | 1 |  |  |  |  | 133 |  | 
| 22 |  |  |  |  |  |  | for (0..255) { | 
| 23 |  |  |  |  |  |  | $uri_escapes{chr($_)} = sprintf("%%%02X", $_); | 
| 24 |  |  |  |  |  |  | } | 
| 25 |  |  |  |  |  |  |  | 
| 26 |  |  |  |  |  |  | sub uri_escape { | 
| 27 | 0 |  |  | 0 | 0 |  | my($text) = @_; | 
| 28 | 0 | 0 |  |  |  |  | return undef unless defined $text; | 
| 29 |  |  |  |  |  |  | # Default unsafe characters.  RFC 2732 ^(uric - reserved) | 
| 30 | 0 | 0 |  |  |  |  | $text =~ s/([^A-Za-z0-9\-_.!~*'()])/$uri_escapes{$1} || sprintf "%%u%04x", ord($1)/ge; | 
|  | 0 |  |  |  |  |  |  | 
| 31 | 0 |  |  |  |  |  | $text; | 
| 32 |  |  |  |  |  |  | } | 
| 33 |  |  |  |  |  |  |  | 
| 34 |  |  |  |  |  |  | 1; |