Skip to content

Commit

Permalink
Item15120: add "safe" encoding of topic title
Browse files Browse the repository at this point in the history
  • Loading branch information
MichaelDaum committed May 5, 2022
1 parent 48a2e22 commit 6e73a00
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 6 deletions.
5 changes: 3 additions & 2 deletions data/System/TopicTitlePlugin.txt
Expand Up @@ -54,7 +54,7 @@ depending on where the !TopicTitle is stored. The most compatible way is to use
| =rev="..."= | revision of the topic | latest revision |
| =default="..."= | default string to return in case the topic does not have a !TopicTitle | !TopicName |
| =hideautoinc="on/off"= | boolean to suppress a return value in case the !TopicName matches =...AUTOINC= or =...XXXXXXXXXX= | off |
| =encode="quotes/url/entity"= | encode the result in the given way. See also [[%SYSTEMWEB%.VarENCODE]] | |
| =encode="quotes/url/entity/safe"= | encode the result in the given way. See also [[%SYSTEMWEB%.VarENCODE]] | |

---++ Perl API

Expand All @@ -73,6 +73,7 @@ on how to read the context flags using the =%IF= makro.
---++ Change History

%TABLE{columnwidths="7em" tablewidth="100%"}%
| 05 Mar 2022 | add "safe" encoding mode |
| 01 Apr 2020 | added support for multilingual topic titles |
| 14 Aug 2018 | fixed renaming a topic changing subsequent topics being saved during the same request |
| 28 May 2018 | improved parsing of topic and web parameter |
Expand All @@ -84,7 +85,7 @@ on how to read the context flags using the =%IF= makro.
%META:FIELD{name="Release" title="Release" value="%25$RELEASE%25"}%
%META:FIELD{name="Description" title="Description" value="%25$SHORTDESCRIPTION%25"}%
%META:FIELD{name="Repository" title="Repository" value="https://github.com/foswiki/%25TOPIC%25"}%
%META:FIELD{name="Copyright" title="Copyright" value="2018-2020 Foswiki Contributors"}%
%META:FIELD{name="Copyright" title="Copyright" value="2018-2022 Foswiki Contributors"}%
%META:FIELD{name="License" title="License" value="GPL ([[http://www.gnu.org/copyleft/gpl.html][GNU General Public License]])"}%
%META:FIELD{name="Home" title="Home" value="https://foswiki.org/Extensions/%25TOPIC%25"}%
%META:FIELD{name="Support" title="Support" value="https://foswiki.org/Support/%25TOPIC%25"}%
6 changes: 3 additions & 3 deletions lib/Foswiki/Plugins/TopicTitlePlugin.pm
@@ -1,6 +1,6 @@
# Plugin for Foswiki - The Free and Open Source Wiki, https://foswiki.org/
#
# TopicTitlePlugin is Copyright (C) 2018-2020 Foswiki Contributors https://foswiki.org
# TopicTitlePlugin is Copyright (C) 2018-2022 Foswiki Contributors https://foswiki.org
#
# This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License
Expand All @@ -20,8 +20,8 @@ use warnings;

use Foswiki::Func ();

our $VERSION = '2.00';
our $RELEASE = '28 Oct 2020';
our $VERSION = '2.10';
our $RELEASE = '05 Mar 2022';
our $SHORTDESCRIPTION = 'Free-form title for topics';
our $NO_PREFS_IN_TOPIC = 1;
our $core;
Expand Down
10 changes: 9 additions & 1 deletion lib/Foswiki/Plugins/TopicTitlePlugin/Core.pm
@@ -1,6 +1,6 @@
# Plugin for Foswiki - The Free and Open Source Wiki, https://foswiki.org/
#
# TopicTitlePlugin is Copyright (C) 2018-2020 Foswiki Contributors https://foswiki.org
# TopicTitlePlugin is Copyright (C) 2018-2022 Foswiki Contributors https://foswiki.org
#
# This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License
Expand Down Expand Up @@ -69,6 +69,7 @@ sub TOPICTITLE {
return _quoteEncode($topicTitle) if $theEncoding eq 'quotes';
return Foswiki::urlEncode($topicTitle) if $theEncoding eq 'url';
return Foswiki::entityEncode($topicTitle) if $theEncoding eq 'entity';
return _safeEncode($topicTitle) if $theEncoding eq 'safe';

return $topicTitle;
}
Expand Down Expand Up @@ -296,4 +297,11 @@ sub _quoteEncode {
return $text;
}

sub _safeEncode {
my $text = shift;

$text =~ s/([<>%'"])/'&#'.ord($1).';'/ge;
return $text;
}

1;

0 comments on commit 6e73a00

Please sign in to comment.