From 3f72b87c0b0295ecd5ce625a156119886eafd599 Mon Sep 17 00:00:00 2001 From: "Kyle J. McKay" Date: Wed, 25 Aug 2021 14:01:23 -0700 Subject: [PATCH] Girocco/Util.pm: add some additional tag validation Signed-off-by: Kyle J. McKay --- Girocco/Util.pm | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/Girocco/Util.pm b/Girocco/Util.pm index 0439960..4039a90 100644 --- a/Girocco/Util.pm +++ b/Girocco/Util.pm @@ -385,6 +385,7 @@ BEGIN { # However, anything in %_oktags is explicitly allowed even if it otherwise # would violate the rules (except that none of [,\s\\\/] are allowed in tags). # Returns the canonical name for the tag if the tag is valid otherwise undef. +# Tags consisting of only underscore characters are never valid unless in %_oktags. sub valid_tag { local $_ = $_[0]; return undef unless defined($_) && $_ ne "" && !/[,\s\/\\]/; @@ -398,8 +399,10 @@ sub valid_tag { return $_canontags{lc($_)} if $fold && exists($_canontags{lc($_)}); return ($fold ? lc($_) : $_) if $_oktags{lc($_)}; return undef unless /^[a-zA-Z][a-zA-Z0-9:.+#_-]+$/; - return undef if $_badtags{lc($_)}; - return undef if /^(.)\1+$/; + my $cu = $_; + $cu =~ tr/:.+#_-//d; + return undef if $cu eq "" || $_badtags{lc($_)} || $_badtags{lc($cu)}; + return undef if /^(.)\1+$/ || $cu =~ /^(.)\1+$/; return length($_) <= 32 ? ($fold ? lc($_) : $_) : undef; } -- 2.11.4.GIT