Author: lslezak
Date: Thu Jan 7 09:59:20 2010
New Revision: 60252
URL: http://svn.opensuse.org/viewcvs/yast?rev=60252&view=rev
Log:
- URL.ycp - escape non-ASCII characters in URL, added URLRecode.pm
module (bnc#446395)
- 2.17.79
Added:
branches/SuSE-Code-11-SP1-Branch/yast2/library/types/src/URLRecode.pm
branches/SuSE-Code-11-SP1-Branch/yast2/library/types/testsuite/tests/URLRecode.err
branches/SuSE-Code-11-SP1-Branch/yast2/library/types/testsuite/tests/URLRecode.out
branches/SuSE-Code-11-SP1-Branch/yast2/library/types/testsuite/tests/URLRecode.ycp
Modified:
branches/SuSE-Code-11-SP1-Branch/yast2/VERSION
branches/SuSE-Code-11-SP1-Branch/yast2/library/types/src/URL.ycp
branches/SuSE-Code-11-SP1-Branch/yast2/library/types/testsuite/tests/URL.out
branches/SuSE-Code-11-SP1-Branch/yast2/library/types/testsuite/tests/URL.ycp
branches/SuSE-Code-11-SP1-Branch/yast2/package/yast2.changes
Modified: branches/SuSE-Code-11-SP1-Branch/yast2/VERSION
URL: http://svn.opensuse.org/viewcvs/yast/branches/SuSE-Code-11-SP1-Branch/yast2/VERSION?rev=60252&r1=60251&r2=60252&view=diff
==============================================================================
--- branches/SuSE-Code-11-SP1-Branch/yast2/VERSION (original)
+++ branches/SuSE-Code-11-SP1-Branch/yast2/VERSION Thu Jan 7 09:59:20 2010
@@ -1 +1 @@
-2.17.78
+2.17.79
Modified: branches/SuSE-Code-11-SP1-Branch/yast2/library/types/src/URL.ycp
URL: http://svn.opensuse.org/viewcvs/yast/branches/SuSE-Code-11-SP1-Branch/yast2/library/types/src/URL.ycp?rev=60252&r1=60251&r2=60252&view=diff
==============================================================================
--- branches/SuSE-Code-11-SP1-Branch/yast2/library/types/src/URL.ycp (original)
+++ branches/SuSE-Code-11-SP1-Branch/yast2/library/types/src/URL.ycp Thu Jan 7 09:59:20 2010
@@ -17,6 +17,7 @@
import "Hostname";
import "String";
import "IP";
+import "URLRecode";
/**
* TODO:
@@ -203,9 +204,9 @@
pth = substring (pth, 1);
}
}
- tokens["path"] = UnEscapeString(pth, transform_map_filename);
- tokens["query"] = UnEscapeString(rawtokens[5]:"", transform_map_query);
- tokens["fragment"] = UnEscapeString(rawtokens[7]:"", transform_map_passwd);
+ tokens["path"] = URLRecode::UnEscape(pth);
+ tokens["query"] = URLRecode::UnEscape(rawtokens[5]:"");
+ tokens["fragment"] = URLRecode::UnEscape(rawtokens[7]:"");
/* Extract username:pass@host:port */
list userpass = regexptokenize(rawtokens[2]:"", "^" +
@@ -219,8 +220,8 @@
);
y2debug("userpass=%1", userpass);
- tokens["user"] = UnEscapeString(userpass[1]:"", transform_map_passwd);
- tokens["pass"] = UnEscapeString(userpass[3]:"", transform_map_passwd);
+ tokens["user"] = URLRecode::UnEscape(userpass[1]:"");
+ tokens["pass"] = URLRecode::UnEscape(userpass[3]:"");
tokens["port"] = userpass[7]:"";
if(userpass[5]:"" != "")
@@ -318,6 +319,8 @@
string url = "";
string userpass = "";
+ y2debug("URL::Build(): input: %1", tokens);
+
if(regexpmatch(tokens["scheme"]:"", "^[[:alpha:]]*$"))
{
/* if (tokens["scheme"]:"" == "samba") url="smb";
@@ -326,12 +329,12 @@
y2debug("url: %1", url);
if (tokens["user"]:"" != "")
{
- userpass = EscapeString(tokens["user"]:"", transform_map_passwd);
+ userpass = URLRecode::EscapePassword(tokens["user"]:"");
y2milestone("Escaped username '%1' => '%2'", tokens["user"]:"", userpass);
}
if (size(userpass) != 0 && tokens["pass"]:"" != "" )
{
- userpass = sformat("%1:%2", userpass, EscapeString(tokens["pass"]:"", transform_map_passwd) );
+ userpass = sformat("%1:%2", userpass, URLRecode::EscapePassword(tokens["pass"]:"") );
}
if (size(userpass) > 0 ) userpass = userpass + "@";
@@ -355,21 +358,22 @@
// path is not empty and doesn't start with "/"
if (tokens["path"]:"" != "" && ! regexpmatch (tokens["path"]:"", "^/"))
- url = sformat("%1/%2", url, EscapeString(tokens["path"]:"", transform_map_filename));
+ url = sformat("%1/%2", url, URLRecode::EscapePath(tokens["path"]:""));
// patch is not empty and starts with "/"
else if (tokens["path"]:"" != "" && regexpmatch (tokens["path"]:"", "^/"))
{
while (substring (tokens["path"]:"", 0, 2) == "//")
tokens["path"] = substring (tokens["path"]:"", 1);
if (tokens["scheme"]:"" == "ftp") {
- url = sformat("%1/%%2f%2", url, substring(EscapeString(tokens["path"]:"", transform_map_filename), 1));
+ url = sformat("%1/%%2f%2", url, substring(URLRecode::EscapePath(tokens["path"]:""), 1));
}
else {
- url = sformat("%1%2", url, EscapeString(tokens["path"]:"", transform_map_filename));
+ url = sformat("%1%2", url, URLRecode::EscapePath(tokens["path"]:""));
}
}
y2debug("url: %1", url);
+
map query_map = MakeMapFromParams(tokens["query"]:"");
if (tokens["scheme"]:"" == "smb" && size(tokens["domain"]:"")>0 && query_map["workgroup"]:"" != tokens["domain"]:"")
@@ -380,9 +384,10 @@
}
if (tokens["query"]:"" != "" )
- url = sformat("%1?%2", url, EscapeString(tokens["query"]:"", transform_map_query));
+ url = sformat("%1?%2", url, URLRecode::EscapeQuery(tokens["query"]:""));
+
if (tokens["fragment"]:"" != "" )
- url = sformat("%1#%2", url, EscapeString(tokens["fragment"]:"", transform_map_passwd));
+ url = sformat("%1#%2", url, URLRecode::EscapePassword(tokens["fragment"]:""));
y2debug("url: %1", url);
if (!Check(url)) {
@@ -390,6 +395,8 @@
return "";
}
+ y2debug("URL::Build(): result: %1", url);
+
return url;
}
Added: branches/SuSE-Code-11-SP1-Branch/yast2/library/types/src/URLRecode.pm
URL: http://svn.opensuse.org/viewcvs/yast/branches/SuSE-Code-11-SP1-Branch/yast2/library/types/src/URLRecode.pm?rev=60252&view=auto
==============================================================================
--- branches/SuSE-Code-11-SP1-Branch/yast2/library/types/src/URLRecode.pm (added)
+++ branches/SuSE-Code-11-SP1-Branch/yast2/library/types/src/URLRecode.pm Thu Jan 7 09:59:20 2010
@@ -0,0 +1,87 @@
+#!/usr/bin/perl -w
+#
+# Author: Ladislav Slezák
+#
+# $Id:$
+#
+# URLRecode.pm
+#
+# This is a replacement for URI::Encode perl module which cannot be used in inst-sys
+# and to decrease the package dependencies
+#
+
+package URLRecode;
+
+use strict;
+use YaST::YCP qw(:LOGGING Boolean sformat);;
+
+our %TYPEINFO;
+use strict;
+
+# local cache for char -> hex string conversion
+our %escape_cache;
+
+# fill the cache
+sub InitCache
+{
+ for(0..255) {$escape_cache{chr($_)} = sprintf("%%%02x", $_);}
+}
+
+
+# Escape password, user name and fragment part of URL string
+# @param input input string
+# @return string Escaped string
+BEGIN{ $TYPEINFO{EscapePassword} = ["function", "string", "string"];}
+sub EscapePassword
+{
+ my ($self, $escaped) = @_;
+
+ if (!defined %escape_cache) { InitCache(); }
+
+ $escaped =~ s/([^A-Za-z0-9\\-_.!~*'()])/$escape_cache{$1}/ge;
+ return $escaped;
+}
+
+# Escape path part of URL string
+# @param input input string
+# @return string Escaped string
+BEGIN{ $TYPEINFO{EscapePath} = ["function", "string", "string"];}
+sub EscapePath
+{
+ my ($self, $escaped) = @_;
+
+ if (!defined %escape_cache) { InitCache() };
+
+ $escaped =~ s/([^A-Za-z0-9\-_.!~*'()\/])/$escape_cache{$1}/ge;
+ return $escaped;
+}
+
+# Escape query part of URL string
+# @param input input string
+# @return string Escaped string
+BEGIN{ $TYPEINFO{EscapeQuery} = ["function", "string", "string"];}
+sub EscapeQuery
+{
+ my ($self, $escaped) = @_;
+
+ if (!defined %escape_cache) { InitCache(); }
+
+ $escaped =~ s/([^A-Za-z0-9\\-_.!~*'()\/:=&])/$escape_cache{$1}/ge;
+ return $escaped;
+}
+
+
+# UnEscape an URL string, replace %<Hexnum><HexNum> sequences
+# by character
+# @param input input string
+# @return string Unescaped string
+BEGIN{ $TYPEINFO{UnEscape} = ["function", "string", "string"];}
+sub UnEscape
+{
+ my ($self, $input) = @_;
+
+ $input =~ s/%([0-9A-Fa-f]{2})/chr(hex($1))/ge;
+ return $input
+}
+
+1;
Modified: branches/SuSE-Code-11-SP1-Branch/yast2/library/types/testsuite/tests/URL.out
URL: http://svn.opensuse.org/viewcvs/yast/branches/SuSE-Code-11-SP1-Branch/yast2/library/types/testsuite/tests/URL.out?rev=60252&r1=60251&r2=60252&view=diff
==============================================================================
--- branches/SuSE-Code-11-SP1-Branch/yast2/library/types/testsuite/tests/URL.out (original)
+++ branches/SuSE-Code-11-SP1-Branch/yast2/library/types/testsuite/tests/URL.out Thu Jan 7 09:59:20 2010
@@ -21,6 +21,8 @@
Return ftp://ftp.example.com/%2fpath/to/dir
Return ftp://ftp.example.com/%2fpath/to/dir
Return ftp://ftp.example.com/%2fpath/to/dir
+Return ftp://ftp.example.com/%2fpath/to/dir?param1=val1¶m2=val2
+Return dir:///path/to/%c4%9b%c5%a1%c4%8d%c5%99%c5%be%c3%bd%c3%a1%c3%ad%c3%a9/dir
Return ftp://[2001:de8:0:f123::1]/%2fpath/to/dir
Return http://[2001:de8:0:f123::1]:8080/path/to/dir
Return $["fragment":"", "host":"2001:de8:0:f123::1", "pass":"", "path":"/path/to/dir", "port":"", "query":"", "scheme":"http", "user":""]
Modified: branches/SuSE-Code-11-SP1-Branch/yast2/library/types/testsuite/tests/URL.ycp
URL: http://svn.opensuse.org/viewcvs/yast/branches/SuSE-Code-11-SP1-Branch/yast2/library/types/testsuite/tests/URL.ycp?rev=60252&r1=60251&r2=60252&view=diff
==============================================================================
--- branches/SuSE-Code-11-SP1-Branch/yast2/library/types/testsuite/tests/URL.ycp (original)
+++ branches/SuSE-Code-11-SP1-Branch/yast2/library/types/testsuite/tests/URL.ycp Thu Jan 7 09:59:20 2010
@@ -10,6 +10,13 @@
{
include "testsuite.ycp";
+map READ = $[
+ "target" : $[
+ "tmpdir" : "/tmp"
+ ]
+];
+TESTSUITE_INIT ([READ], nil);
+
import "URL";
TEST(``(URL::Parse("http://name:pass@www.suse.cz:80/path/index.html?question#part")), [], nil);
@@ -50,6 +57,10 @@
TEST(``(URL::Build($["scheme":"ftp","host":"ftp.example.com","path":"/path/to/dir"])), [], nil);
TEST(``(URL::Build($["scheme":"ftp","host":"ftp.example.com","path":"//path/to/dir"])), [], nil);
TEST(``(URL::Build($["scheme":"ftp","host":"ftp.example.com","path":"///path/to/dir"])), [], nil);
+TEST(``(URL::Build($["scheme":"ftp","host":"ftp.example.com","path":"///path/to/dir", "query" : "param1=val1¶m2=val2" ])), [], nil);
+
+// bnc #446395 - non-ASCII chars in path must be escaped
+TEST(``(URL::Build($["scheme":"dir", "path":"/path/to/ÄÅ¡ÄÅžýáÃé/dir"])), [], nil);
// IPv6 tests
TEST(``(URL::Build($["scheme":"ftp","host":"2001:de8:0:f123::1","path":"///path/to/dir"])), [], nil);
Added: branches/SuSE-Code-11-SP1-Branch/yast2/library/types/testsuite/tests/URLRecode.err
URL: http://svn.opensuse.org/viewcvs/yast/branches/SuSE-Code-11-SP1-Branch/yast2/library/types/testsuite/tests/URLRecode.err?rev=60252&view=auto
==============================================================================
(empty)
Added: branches/SuSE-Code-11-SP1-Branch/yast2/library/types/testsuite/tests/URLRecode.out
URL: http://svn.opensuse.org/viewcvs/yast/branches/SuSE-Code-11-SP1-Branch/yast2/library/types/testsuite/tests/URLRecode.out?rev=60252&view=auto
==============================================================================
--- branches/SuSE-Code-11-SP1-Branch/yast2/library/types/testsuite/tests/URLRecode.out (added)
+++ branches/SuSE-Code-11-SP1-Branch/yast2/library/types/testsuite/tests/URLRecode.out Thu Jan 7 09:59:20 2010
@@ -0,0 +1,7 @@
+Return nil
+Return
+Return /%40%23%24%25%5e%26/dir/%c4%8d%c3%bd%c4%9b%c5%a1%c4%8d%c3%bd%c3%a1/file
+Return true
+Return %20!%40%23%24%25%5e%26*()/%3f%2b%3d
+Return %20!%40%23%24%25^%26*()%2f%3f%2b%3d
+Return %20!%40%23%24%25^&*()/%3f%2b=
Added: branches/SuSE-Code-11-SP1-Branch/yast2/library/types/testsuite/tests/URLRecode.ycp
URL: http://svn.opensuse.org/viewcvs/yast/branches/SuSE-Code-11-SP1-Branch/yast2/library/types/testsuite/tests/URLRecode.ycp?rev=60252&view=auto
==============================================================================
--- branches/SuSE-Code-11-SP1-Branch/yast2/library/types/testsuite/tests/URLRecode.ycp (added)
+++ branches/SuSE-Code-11-SP1-Branch/yast2/library/types/testsuite/tests/URLRecode.ycp Thu Jan 7 09:59:20 2010
@@ -0,0 +1,27 @@
+/**
+ * Testsuite for URLRecode.pm module
+ *
+ * $Id: URLRecode.ycp 57027 2009-04-29 10:24:13Z lslezak $
+ */
+
+{
+
+include "testsuite.ycp";
+import "URLRecode";
+
+
+TEST(``(URLRecode::EscapePath(nil)), [], nil);
+TEST(``(URLRecode::EscapePath("")), [], nil);
+
+string test_path = "/@#$%^&/dir/ÄýÄÅ¡Äýá/file";
+
+TEST(``(URLRecode::EscapePath(test_path)), [], nil);
+TEST(``(URLRecode::UnEscape(URLRecode::EscapePath(test_path)) == test_path), [], nil);
+
+
+TEST(``(URLRecode::EscapePath(" !@#$%^&*()/?+=")), [], nil);
+TEST(``(URLRecode::EscapePassword(" !@#$%^&*()/?+=")), [], nil);
+TEST(``(URLRecode::EscapeQuery(" !@#$%^&*()/?+=")), [], nil);
+
+/* EOF */
+}
Modified: branches/SuSE-Code-11-SP1-Branch/yast2/package/yast2.changes
URL: http://svn.opensuse.org/viewcvs/yast/branches/SuSE-Code-11-SP1-Branch/yast2/package/yast2.changes?rev=60252&r1=60251&r2=60252&view=diff
==============================================================================
--- branches/SuSE-Code-11-SP1-Branch/yast2/package/yast2.changes (original)
+++ branches/SuSE-Code-11-SP1-Branch/yast2/package/yast2.changes Thu Jan 7 09:59:20 2010
@@ -1,4 +1,11 @@
-------------------------------------------------------------------
+Thu Jan 7 08:20:23 UTC 2010 - lslezak@suse.cz
+
+- URL.ycp - escape non-ASCII characters in URL, added URLRecode.pm
+ module (bnc#446395)
+- 2.17.79
+
+-------------------------------------------------------------------
Tue Jan 5 15:07:54 UTC 2010 - lslezak@suse.cz
- added missing UI::SetProductName() call - display the proper
--
To unsubscribe, e-mail: yast-commit+unsubscribe@opensuse.org
For additional commands, e-mail: yast-commit+help@opensuse.org