[interchange-cvs] interchange - racke modified 2 files
interchange-core@interchange.redhat.com
interchange-core@interchange.redhat.com
Fri Feb 1 16:09:01 2002
User: racke
Date: 2002-02-01 21:08:27 GMT
Modified: lib/Vend Interpolate.pm Util.pm
Log:
revert back the Vend::Interpolate::scan_escape behaviour to not
escape non-word characters (that is different from the behaviour
in stable)
introduced new Vend::Util::escape_scan_url function which escapes
unsafe characters in string (I consider the = sign safe in opposite of
what URI::Escape says, because it looks to ugly and is bloat
in IMHO to escape it)
therefore finally these things should work:
[area href="Catalog/Food/Hot Dogs"]
[area href="scan/lf=category/ls=%Hot Dogs"]
Revision Changes Path
2.52 +10 -15 interchange/lib/Vend/Interpolate.pm
rev 2.52, prev_rev 2.51
Index: Interpolate.pm
===================================================================
RCS file: /anon_cvs/repository/interchange/lib/Vend/Interpolate.pm,v
retrieving revision 2.51
retrieving revision 2.52
diff -u -r2.51 -r2.52
--- Interpolate.pm 1 Feb 2002 13:41:28 -0000 2.51
+++ Interpolate.pm 1 Feb 2002 21:08:26 -0000 2.52
@@ -1,6 +1,6 @@
# Vend::Interpolate - Interpret Interchange tags
#
-# $Id: Interpolate.pm,v 2.51 2002/02/01 13:41:28 racke Exp $
+# $Id: Interpolate.pm,v 2.52 2002/02/01 21:08:26 racke Exp $
#
# Copyright (C) 1996-2001 Red Hat, Inc. <interchange@redhat.com>
#
@@ -27,7 +27,7 @@
require Exporter;
@ISA = qw(Exporter);
-$VERSION = substr(q$Revision: 2.51 $, 10);
+$VERSION = substr(q$Revision: 2.52 $, 10);
@EXPORT = qw (
@@ -2817,7 +2817,7 @@
# Escapes a scan reliably in three different possible ways
sub escape_scan {
- my ($scan, $ref, $esc) = @_;
+ my ($scan, $ref) = @_;
#::logDebug("escape_scan: scan=$scan");
if (ref $scan) {
for(@$scan) {
@@ -2849,7 +2849,7 @@
}
}
- return join '/', 'scan', escape_mv('/', $scan, undef, $esc);
+ return join '/', 'scan', escape_mv('/', $scan);
}
sub escape_mv {
@@ -2873,13 +2873,8 @@
for(@args) {
s!/!__SLASH__!g unless defined $not_scan;
s!\0!-_NULL_-!g;
- if ($esc) {
- s!(\w\w=)(.*)!$1 . esc($2)!eg
- or (undef $_, next);
- } else {
- m!\w=!
- or (undef $_, next);
- }
+ m!\w=!
+ or (undef $_, next);
s!__SLASH__!::!g unless defined $not_scan;
}
return join $joiner, grep(defined $_, @args);
@@ -2968,10 +2963,10 @@
return '<A HREF="' . form_link(@_) . '">' if defined $opt and $opt->{form};
if ($opt->{search}) {
- $page = escape_scan($opt->{search},undef,1);
+ $page = escape_scan($opt->{search});
}
elsif ($page eq 'scan') {
- $page = escape_scan($arg,undef,1);
+ $page = escape_scan($arg);
undef $arg;
}
@@ -2994,10 +2989,10 @@
$page = '' if ! defined $page;
if ($opt->{search}) {
- $page = escape_scan($opt->{search},undef,1);
+ $page = escape_scan($opt->{search});
}
elsif ($page eq 'scan') {
- $page = escape_scan($arg,undef,1);
+ $page = escape_scan($arg);
undef $arg;
}
2.19 +35 -6 interchange/lib/Vend/Util.pm
rev 2.19, prev_rev 2.18
Index: Util.pm
===================================================================
RCS file: /anon_cvs/repository/interchange/lib/Vend/Util.pm,v
retrieving revision 2.18
retrieving revision 2.19
diff -u -r2.18 -r2.19
--- Util.pm 1 Feb 2002 17:03:38 -0000 2.18
+++ Util.pm 1 Feb 2002 21:08:27 -0000 2.19
@@ -1,6 +1,6 @@
# Vend::Util - Interchange utility functions
#
-# $Id: Util.pm,v 2.18 2002/02/01 17:03:38 jon Exp $
+# $Id: Util.pm,v 2.19 2002/02/01 21:08:27 racke Exp $
#
# Copyright (C) 1996-2001 Red Hat, Inc. <interchange@redhat.com>
#
@@ -81,7 +81,7 @@
use Safe;
use subs qw(logError logGlobal);
use vars qw($VERSION @EXPORT @EXPORT_OK);
-$VERSION = substr(q$Revision: 2.18 $, 10);
+$VERSION = substr(q$Revision: 2.19 $, 10);
BEGIN {
eval {
@@ -106,6 +106,13 @@
'-:_.$/'
;
+$ESCAPE_CHARS::ok_in_url =
+ 'ABCDEFGHIJKLMNOPQRSTUVWXYZ' .
+ 'abcdefghijklmnopqrstuvwxyz' .
+ '0123456789' .
+ '-_./~='
+ ;
+
my $need_escape;
sub setup_escape_chars {
@@ -120,11 +127,17 @@
$t = $a;
}
$ESCAPE_CHARS::translate[$i] = $t;
+ if (index($ESCAPE_CHARS::ok_in_url,$a) == -1) {
+ $t = '%' . sprintf( "%02X", $i );
+ }
+ else {
+ $t = $a;
+ }
+ $ESCAPE_CHARS::translate_url[$i] = $t;
}
- my $string = "[^$ESCAPE_CHARS::ok_in_filename]";
- $need_escape = qr{$string=};
-
+ my $string = "[^$ESCAPE_CHARS::ok_in_url]";
+ $need_escape = qr{$string};
}
# Replace any characters that might not be safe in a filename (especially
@@ -143,6 +156,22 @@
return $r;
}
+# Replace any characters that might not be safe in an URL
+# with the %HH notation.
+
+sub escape_chars_url {
+ my($in) = @_;
+ my($c, $r);
+
+ $r = '';
+ foreach $c (split(//, $in)) {
+ $r .= $ESCAPE_CHARS::translate_url[ord($c)];
+ }
+
+ # safe now
+ return $r;
+}
+
# Returns its arguments as a string of tab-separated fields. Tabs in the
# argument values are converted to spaces.
@@ -1180,7 +1209,7 @@
$ct = ++$Vend::Session->{pageCount}
unless $can_cache and $::Scratch->{mv_no_count};
- $path = escape_chars($path)
+ $path = escape_chars_url($path)
if $path =~ $need_escape;
$r .= '/' . $path;
$r .= '.html' if $::Scratch->{mv_add_dot_html} and $r !~ /\.html?$/;