Updating branch refs/heads/master to c8d277436485d67d1b6829ac438d15ceafdf1dbc (commit) from a363a6dcc05113d874e8dd1a4062b9df51d3873f (commit)
commit c8d277436485d67d1b6829ac438d15ceafdf1dbc Author: Christian Dywan <christ...@twotoasts.de> Date: Fri Sep 28 19:07:54 2012 +0200 Don't include query in suggested filenames midori/midori-download.vala | 11 ++++++----- tests/download.vala | 22 +++++++++++++++++----- 2 files changed, 23 insertions(+), 10 deletions(-) diff --git a/midori/midori-download.vala b/midori/midori-download.vala index cc8c539..72f52f1 100644 --- a/midori/midori-download.vala +++ b/midori/midori-download.vala @@ -225,10 +225,9 @@ namespace Midori { } public string get_filename_suggestion_for_uri (string mime_type, string uri) { - /* Try to provide a good default filename, UTF-8 encoded */ - string filename = clean_filename (Soup.URI.decode (uri)); - /* Take the rest of the URI if needed */ - if (filename.has_suffix ("/") || uri.index_of_char ('.') == -1) + return_if_fail (Midori.URI.is_location (uri)); + string filename = File.new_for_uri (uri).get_basename (); + if (uri.index_of_char ('.') == -1) return Path.build_filename (filename, fallback_extension (null, mime_type)); return filename; } @@ -244,8 +243,10 @@ namespace Midori { int period = uri.last_index_of_char ('.', last_slash); if (period == -1) return null; + /* Exclude the query: ?query=foobar */ + int query = uri.last_index_of_char ('?', period); /* The extension, or "." if it ended with a period */ - string extension = uri.substring (period, -1); + string extension = uri.substring (period, query - period); if (&basename != null) basename = uri.substring (0, period); return extension; diff --git a/tests/download.vala b/tests/download.vala index c5e0f98..746cba2 100644 --- a/tests/download.vala +++ b/tests/download.vala @@ -11,19 +11,30 @@ struct TestCase { public string data; - public string? expected; + public string mime_type; + public string? expected_filename; + public string? expected_extension; } const TestCase[] filenames = { - { "/tmp/midori-user/tumblr123.jpg", ".jpg" }, - { "https://green.cat/8019B6/a.b/500.jpg", ".jpg" }, - { "http://example.com/file.png", ".png" } + { "file:///tmp/midori-user/tumblr123.jpg", "image/jpg", "tumblr123.jpg", ".jpg" }, + { "https://green.cat/8019B6/a.b/500.jpg", "image/jpg", "500.jpg", ".jpg" }, + { "http://example.com/file.png", "image/png", "file.png", ".png" }, + { "http://svn.sf.net/doc/doxy_to_dev.xsl.m4?rev=253", "application/xslt+xml", "doxy_to_dev.xsl.m4", ".m4" } }; +static void download_suggestion () { + foreach (var filename in filenames) { + string? result = Midori.Download.get_filename_suggestion_for_uri ( + filename.mime_type, filename.data); + Katze.assert_str_equal (filename.data, result, filename.expected_filename); + } +} + static void download_extension () { foreach (var filename in filenames) { string? result = Midori.Download.get_extension_for_uri (filename.data); - Katze.assert_str_equal (filename.data, result, filename.expected); + Katze.assert_str_equal (filename.data, result, filename.expected_extension); } } @@ -51,6 +62,7 @@ static void download_unique () { void main (string[] args) { Test.init (ref args); + Test.add_func ("/download/suggestion", download_suggestion); Test.add_func ("/download/extension", download_extension); Test.add_func ("/download/unique", download_unique); Test.run (); _______________________________________________ Xfce4-commits mailing list Xfce4-commits@xfce.org https://mail.xfce.org/mailman/listinfo/xfce4-commits