[interchange-cvs] interchange - jon modified 2 files
interchange-cvs at icdevgroup.org
interchange-cvs at icdevgroup.org
Thu Apr 17 22:50:33 UTC 2008
User: jon
Date: 2008-04-17 22:50:33 GMT
Modified: lib/Vend CharSet.pm Interpolate.pm
Log:
Fix regexes that use UTF-8 inside a Safe compartment.
Patch by Sonny Cook <sonny at endpoint.com>, with some logging tweaks by me.
Revision Changes Path
2.7 interchange/lib/Vend/CharSet.pm
rev 2.7, prev_rev 2.6
Index: CharSet.pm
===================================================================
RCS file: /var/cvs/interchange/lib/Vend/CharSet.pm,v
retrieving revision 2.6
retrieving revision 2.7
diff -u -u -r2.6 -r2.7
--- CharSet.pm 17 Apr 2008 10:52:37 -0000 2.6
+++ CharSet.pm 17 Apr 2008 22:50:33 -0000 2.7
@@ -1,8 +1,9 @@
# Vend::CharSet - utility methods for handling character encoding
#
-# $Id: CharSet.pm,v 2.6 2008-04-17 10:52:37 racke Exp $
+# $Id: CharSet.pm,v 2.7 2008-04-17 22:50:33 jon Exp $
#
# Copyright (C) 2008 Interchange Development Group
+# Copyright (C) 2008 Sonny Cook <sonny at endpoint.com>
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
@@ -48,7 +49,7 @@
my ($class, $encoding, $octets) = @_;
#::logDebug("to_internal - converting octets from $encoding to internal");
if (!$encoding || is_utf8($octets)) {
-#::logDebug("to_internal - octets are already utf-8 flagged");
+#::logDebug("to_internal - octets are already UTF-8 flagged");
return $octets;
}
@@ -70,6 +71,27 @@
return $c->{Variable}{MV_HTTP_CHARSET} || $Global::Variable->{MV_HTTP_CHARSET};
}
+# This is a workaround for the problem with UTF-8 regular expressions
+# implicitly trying to require UTF-8
+sub utf8_safe_regex_workaround {
+ my ($class, $compartment) = @_;
+
+ $_ = 'workaround for the workaround';
+ s/\p{SpacePerl}+$//;
+
+#::logDebug("Attempting to set UTF-8 safe regex workaround");
+
+ $compartment->untrap(qw/require caller dofile sort entereval/);
+ $compartment->reval('$_ = "\x{30AE}"; s/[abc]/x/ig');
+ $@ and ::logError("Part of UTF-8 safe regex workaround failed (this may not be a bug): %s", $@);
+ $compartment->trap(qw/require caller dofile sort entereval/);
+
+ # check and see if it worked, if not, then we might have problems later
+ $compartment->reval('$_ = "\x{30AE}"; s/[abc]/x/ig');
+
+ $@ and ::logError("UTF-8 regular expressions in a Safe compartment are not working properly. This may affect code in perl or calc blocks in your pages if you are processing UTF-8 strings in them. Error: %s", $@);
+}
+
# this sub taken from the perluniintro man page, for diagnostic purposes
sub display_chars {
return unless $_[0];
@@ -84,6 +106,4 @@
}
-
1;
-
2.299 interchange/lib/Vend/Interpolate.pm
rev 2.299, prev_rev 2.298
Index: Interpolate.pm
===================================================================
RCS file: /var/cvs/interchange/lib/Vend/Interpolate.pm,v
retrieving revision 2.298
retrieving revision 2.299
diff -u -u -r2.298 -r2.299
--- Interpolate.pm 25 Mar 2008 17:13:21 -0000 2.298
+++ Interpolate.pm 17 Apr 2008 22:50:33 -0000 2.299
@@ -1,6 +1,6 @@
# Vend::Interpolate - Interpret Interchange tags
#
-# $Id: Interpolate.pm,v 2.298 2008-03-25 17:13:21 jon Exp $
+# $Id: Interpolate.pm,v 2.299 2008-04-17 22:50:33 jon Exp $
#
# Copyright (C) 2002-2008 Interchange Development Group
# Copyright (C) 1996-2002 Red Hat, Inc.
@@ -28,7 +28,7 @@
require Exporter;
@ISA = qw(Exporter);
-$VERSION = substr(q$Revision: 2.298 $, 10);
+$VERSION = substr(q$Revision: 2.299 $, 10);
@EXPORT = qw (
@@ -178,6 +178,10 @@
$ready_safe = new Safe $pkg;
$ready_safe->share_from('MVSAFE', ['$safe']);
#::logDebug("new safe made=$ready_safe->{Root}");
+
+ Vend::CharSet->utf8_safe_regex_workaround($ready_safe)
+ if $::Variable->{MV_UTF8};
+
$ready_safe->trap(@{$Global::SafeTrap});
$ready_safe->untrap(@{$Global::SafeUntrap});
no strict 'refs';
@@ -1198,6 +1202,8 @@
last RUNSAFE;
}
+ Vend::CharSet->utf8_safe_regex_workaround($ready_safe)
+ if $::Variable->{MV_UTF8};
$ready_safe->trap(@{$Global::SafeTrap});
$ready_safe->untrap(@{$Global::SafeUntrap});
$status = $ready_safe->reval($op) ? 1 : 0;
More information about the interchange-cvs
mailing list