You are here: Foswiki>Tasks Web>Item13916 (11 Jan 2017, GeorgeClark)Edit Attach

Item13916: TagMePlugin need switch for utf8 when it used Foswiki::Func::saveFile|readFile.

pencil
Priority: Normal
Current State: Closed
Released In: n/a
Target Release: n/a
Applies To: Extension
Component: TagMePlugin
Branches: master
Reported By: StanleyTweedle
Waiting For:
Last Change By: GeorgeClark
Foswiki::Func::saveFile|readFile need switch on call for use with utf8(like described in engine).

Now list tag encodes in utf8 twice after edit or add tag.

-- StanleyTweedle - 08 Jan 2016

It's also not correctly handling encode/decode of unicode web & topic names. Try the following patch

diff --git a/lib/Foswiki/Plugins/TagMePlugin.pm b/lib/Foswiki/Plugins/TagMePlugin.pm
index 78fce0c..6adf207 100644
--- a/lib/Foswiki/Plugins/TagMePlugin.pm
+++ b/lib/Foswiki/Plugins/TagMePlugin.pm
@@ -1402,7 +1402,7 @@ sub _readTagInfo {
     my ($webTopic) = @_;
 
     $webTopic =~ s/[\/\\]/\./g;
-    my $text = Foswiki::Func::readFile("$workAreaDir/_tags_$webTopic.txt");
+    my $text = Foswiki::Func::readFile("$workAreaDir/_tags_$webTopic.txt", 1);
     my @info = grep { /^[0-9]/ } split( /\n/, $text );
     return @info;
 }
@@ -1415,7 +1415,7 @@ sub _writeTagInfo {
     if ( scalar @info ) {
         my $text = "# This file is generated, do not edit\n"
           . join( "\n", reverse sort @info ) . "\n";
-        Foswiki::Func::saveFile( $file, $text );
+        Foswiki::Func::saveFile( $file, $text, 1 );
     }
     elsif ( -e $file ) {
         unlink($file);
@@ -1431,15 +1431,15 @@ sub renameTagInfo {
     my $oldFile = "$workAreaDir/_tags_$oldWebTopic.txt";
     my $newFile = "$workAreaDir/_tags_$newWebTopic.txt";
     if ( -e $oldFile ) {
-        my $text = Foswiki::Func::readFile($oldFile);
-        Foswiki::Func::saveFile( $newFile, $text );
+        my $text = Foswiki::Func::readFile($oldFile, 1);
+        Foswiki::Func::saveFile( $newFile, $text, 1 );
         unlink($oldFile);
     }
 }
 
 # =========================
 sub _readAllTags {
-    my $text = Foswiki::Func::readFile("$workAreaDir/_tags_all.txt");
+    my $text = Foswiki::Func::readFile("$workAreaDir/_tags_all.txt", 1);
 
     #my @tags = grep{ /^[${alphaNum}_]/ } split( /\n/, $text );
     # we assume that this file has been written by TagMe, so tags should be
@@ -1455,7 +1455,7 @@ sub writeAllTags {
     my (@tags) = @_;
     my $text = "# This file is generated, do not edit\n"
       . join( "\n", sort { lc $a cmp lc $b } @tags ) . "\n";
-    Foswiki::Func::saveFile( "$workAreaDir/_tags_all.txt", $text );
+    Foswiki::Func::saveFile( "$workAreaDir/_tags_all.txt", $text, 1 );
 }
 
 # =========================
@@ -1744,16 +1744,14 @@ sub _htmlPostChangeRequestFormField {
 
 # =========================
 sub _urlEncode {
-    my $text = shift;
-    $text =~ s/([^0-9a-zA-Z-_.:~!*'()\/%])/'%'.sprintf('%02x',ord($1))/ge;
-    return $text;
+    # Foswiki 2.x  use core urlEncode
+    return Foswiki::urlEncode( $_[0] );
 }
 
 # =========================
 sub _urlDecode {
-    my $text = shift;
-    $text =~ s/%([\da-f]{2})/chr(hex($1))/gei;
-    return $text;
+    # Foswiki 2.x  urlDecode not required.
+    return $_[0];
 }
 
 # =========================
@@ -1765,7 +1763,7 @@ sub _handleMakeText {
 
     # very crude hack to remove MAKETEXT{"...."}
     # Note: parameters are _not_ supported!
-    $_[0] =~ s/[%]MAKETEXT{ *\"(.*?)." *}%/$1/go;
+    $_[0] =~ s/[%]MAKETEXT\{ *\"(.*?)." *\}%/$1/go;
 }
 
 # =========================

Note that this isn't in a final form - it would break compatibility with Foswiki 1.x

-- GeorgeClark - 09 Jan 2017

Uploaded version 2.2, tested on Foswiki 2.1 and 1.1.9.

-- GeorgeClark - 11 Jan 2017
 
Topic revision: r6 - 11 Jan 2017, GeorgeClark
The copyright of the content on this website is held by the contributing authors, except where stated elsewhere. See Copyright Statement. Creative Commons License    Legal Imprint    Privacy Policy