Skip to content

Commit

Permalink
Item13917: clean up regexes, and fix comparison of PERL types for reset
Browse files Browse the repository at this point in the history
  • Loading branch information
Crawford Currie committed Jan 14, 2016
1 parent fe9fb03 commit 33494cb
Show file tree
Hide file tree
Showing 3 changed files with 61 additions and 5 deletions.
55 changes: 54 additions & 1 deletion ConfigurePlugin/pub/System/ConfigurePlugin/types.uncompressed.js
Original file line number Diff line number Diff line change
Expand Up @@ -181,6 +181,43 @@ var Types = {};
Types.REGEX = Types.STRING.extend({
});

// Deep compare of simple object, used for perl simple structures.
// Note: no support for built-in types other than the basic types, arrays
// and hashes; but then parsing a perl value use eval will never succeed with
// anything else.
Types.deep_equals = function(x, y) {
if (x === y)
return true;

if (x === null
|| x === undefined
|| y === null
|| y === undefined)
return false; // x===y would have succeeded otherwise

if (x.constructor !== y.constructor)
return false;

if (x.valueOf() === y.valueOf())
return true;

if (Array.isArray(x) && x.length !== y.length)
return false;

// if they are strictly equal, they both need to be object at least
if (!(x instanceof Object && y instanceof Object))
return false;

// recursive equality check
var p = Object.keys(x);
return Object.keys(y).every(function (i) {
return p.indexOf(i) !== -1;
}) &&
p.every(function (i) {
return Types.deep_equals(x[i], y[i]);
});
};

Types.PERL = Types.BaseType.extend({
createUI: function(change_handler) {
if (!(this.spec.SIZE && this.spec.SIZE.match(/\b(\d+)x(\d+)\b/))) {
Expand All @@ -189,8 +226,24 @@ var Types = {};
return this._super(change_handler);
},
isDefault: function() {
// To do this comparison requires parsing and rewriting the perl to
// javascript. Not impossible, but tricky.
var a = this.currentValue().trim(),
b = this.spec['default'].trim();
b = this.spec['default'].trim(), av, bv;
try {
// See if they parse as JS - they probably will! If they don't,
// parse, fall back to a string comparison :-(
av = eval(a);
bv = eval(b);
} catch (err) {
av = null; bv = null;
}
if (av !== null && bv !== null) {
return Types.deep_equals(av, bv);
}
// String comparison of the serialised perl value. This is unlikely
// to work, but there's no other option if one or both of the values
// fails to parse using JS eval.
return a === b;
}

Expand Down
5 changes: 4 additions & 1 deletion core/lib/Foswiki.pm
Original file line number Diff line number Diff line change
Expand Up @@ -373,7 +373,10 @@ BEGIN {
require locale;
import locale();
}
elsif (DEBUG) {

# Set environment var FOSWIKI_NOTAINT to disable taint checks even
# if Taint::Runtime is installed
elsif ( DEBUG && !$ENV{FOSWIKI_NOTAINT} ) {
eval { require Taint::Runtime; };
if ($@) {
print STDERR
Expand Down
6 changes: 3 additions & 3 deletions core/lib/Foswiki.spec
Original file line number Diff line number Diff line change
Expand Up @@ -461,7 +461,7 @@ $Foswiki::cfg{TemplateLogin}{AllowLoginUsingEmailAddress} = 0;
# environments may require funny characters in login names, such as \.
# This is a filter *in* expression, so a login name must match this
# expression or an error will be thrown and the login denied.
$Foswiki::cfg{LoginNameFilterIn} = '^[^\s\*?~^\$@%`"\'&;|<>\x00-\x1f]+$';
$Foswiki::cfg{LoginNameFilterIn} = '^[^\\s\\*?~^\\$@%`"\'&;|<>\x00-\x1f]+$';

# **STRING 20 LABEL="Default User Login" EXPERT**
# Guest user's login name. You are recommended not to change this.
Expand Down Expand Up @@ -981,13 +981,13 @@ $Foswiki::cfg{UploadFilter} = '^((?i)\.htaccess|.*\.(?i)(?:php[0-9s]?(\..*)?|[sp
# include paths and skin names. This is a filter *out*, so if any of the
# characters matched by this expression are seen in names, they will be
# removed.
$Foswiki::cfg{NameFilter} = '[\\\\\s*?~^$@%`"\'&|<;:>\[\]#\x00-\x1f]';
$Foswiki::cfg{NameFilter} = '[\s*?~^$@%`"\'&|<:>\[\]#\x00-\x1f]';

# **REGEX LABEL="Attachment Name Filter" EXPERT**
# Filter-out regex file attachment names. This is a filter *out*, so if any of the
# characters matched by this expression are seen in an attachment name, they will be
# removed.
$Foswiki::cfg{AttachmentNameFilter} = '[\\\\*?~^$@%`"\'&|<;>\[\]#\x00-\x1f]';
$Foswiki::cfg{AttachmentNameFilter} = '[*?~^$@%`"\'&|<>\[\]#\x00-\x1f]';

# **BOOLEAN LABEL="Replace Attachment Spaces" EXPERT**
# Enable this parameter if you want the old behavior of replacing spaces in an attachment filename
Expand Down

0 comments on commit 33494cb

Please sign in to comment.