diff --git a/uppsrc/Core/Inet.h b/uppsrc/Core/Inet.h index c4a62ac44..3e0e7f600 100644 --- a/uppsrc/Core/Inet.h +++ b/uppsrc/Core/Inet.h @@ -7,9 +7,9 @@ String MIMECharsetName(byte charset); String UrlEncode(const char *s, const char *end); String UrlEncode(const char *s, int len); String UrlEncode(const String& s); -String UrlDecode(const char *s, const char *end); -String UrlDecode(const char *s, int len); -String UrlDecode(const String& s); +String UrlDecode(const char *s, const char *end, bool plus_is_space = true); +String UrlDecode(const char *s, int len, bool plus_is_space = true); +String UrlDecode(const String& s, bool plus_is_space = true); String QPEncode(const char* s); String QPDecode(const char *s, bool undescore_to_space = false); diff --git a/uppsrc/Core/InetUtil.cpp b/uppsrc/Core/InetUtil.cpp index e52e39e18..b3e97c382 100644 --- a/uppsrc/Core/InetUtil.cpp +++ b/uppsrc/Core/InetUtil.cpp @@ -119,10 +119,7 @@ String UrlEncode(const char *p, const char *e) out.Cat(b, int(p - b)); if(p >= e) break; - if(*p == ' ') - out << '+'; - else - out << '%' << hex_digits[(*p >> 4) & 15] << hex_digits[*p & 15]; + out << '%' << hex_digits[(*p >> 4) & 15] << hex_digits[*p & 15]; } return String(out); } @@ -137,12 +134,12 @@ String UrlEncode(const String& s) return UrlEncode(~s, s.GetLength()); } -String UrlDecode(const char *b, const char *e) +String UrlDecode(const char *b, const char *e, bool plus_is_space) { StringBuffer out; byte d1, d2, d3, d4; for(const char *p = b; p < e; p++) - if(*p == '+') + if(*p == '+' && plus_is_space) out.Cat(' '); else if(*p == '%' && (d1 = ctoi(p[1])) < 16 && (d2 = ctoi(p[2])) < 16) { out.Cat(d1 * 16 + d2); @@ -159,14 +156,14 @@ String UrlDecode(const char *b, const char *e) return String(out); } -String UrlDecode(const char *s, int len) +String UrlDecode(const char *s, int len, bool plus_is_space) { - return UrlDecode(s, s + len); + return UrlDecode(s, s + len, plus_is_space); } -String UrlDecode(const String& s) +String UrlDecode(const String& s, bool plus_is_space) { - return UrlDecode(~s, s.GetLength()); + return UrlDecode(~s, s.GetLength(), plus_is_space); } String QPEncode(const char* s) diff --git a/uppsrc/Core/src.tpp/Inet_en-us.tpp b/uppsrc/Core/src.tpp/Inet_en-us.tpp index a354ac25e..4abb6cfec 100644 --- a/uppsrc/Core/src.tpp/Inet_en-us.tpp +++ b/uppsrc/Core/src.tpp/Inet_en-us.tpp @@ -1,5 +1,4 @@ topic "Internet utility"; -[2 $$0,0#00000000000000000000000000000000:Default] [i448;a25;kKO9;2 $$1,0#37138531426314131252341829483380:class] [l288;2 $$2,2#27521748481378242620020725143825:desc] [0 $$3,0#96390100711032703541132217272105:end] @@ -9,6 +8,7 @@ topic "Internet utility"; [l288;i1121;b17;O9;~~~.1408;2 $$7,0#10431211400427159095818037425705:param] [i448;b42;O9;2 $$8,8#61672508125594000341940100500538:tparam] [b42;2 $$9,9#13035079074754324216151401829390:normal] +[2 $$0,0#00000000000000000000000000000000:Default] [{_} [ {{10000@(113.42.0) [s0;%% [*@7;4 Internet format utility functions]]}}&] [s3; &] @@ -46,14 +46,20 @@ space is represented by `'`+`' and anything else as %HH, where HH is two digit hexadecimal number.&] [s3;%% &] [s4; &] -[s5;:UrlDecode`(const char`*`,const char`*`): [_^String^ String]_[* UrlDecode]([@(0.0.255) c -onst]_[@(0.0.255) char]_`*[*@3 s], [@(0.0.255) const]_[@(0.0.255) char]_`*[*@3 end])&] -[s5;:UrlDecode`(const char`*`,int`): [_^String^ String]_[* UrlDecode]([@(0.0.255) const]_[@(0.0.255) c -har]_`*[*@3 s], [@(0.0.255) int]_[*@3 len])&] -[s5;:UrlDecode`(const String`&`): [_^String^ String]_[* UrlDecode]([@(0.0.255) const]_[_^String^ S -tring][@(0.0.255) `&]_[*@3 s])&] -[s2;%% Decodes data as required by [^http`:`/`/www`.w3`.org`/TR`/html401`/interact`/forms`.html`#h`-17`.13`.4`.1^ M -IME type application/x`-www`-form`-urlencoded] (see UrlEncode).&] +[s5;:Upp`:`:UrlDecode`(const char`*`,const char`*`,bool`): String +[* UrlDecode]([@(0.0.255) const] [@(0.0.255) char] [@(0.0.255) `*][*@3 b], +[@(0.0.255) const] [@(0.0.255) char] [@(0.0.255) `*][*@3 e], [@(0.0.255) bool] +[*@3 plus`_is`_space] [@(0.0.255) `=] [@(0.0.255) true])&] +[s5;:Upp`:`:UrlDecode`(const char`*`,int`,bool`): String [* UrlDecode]([@(0.0.255) const] +[@(0.0.255) char] [@(0.0.255) `*][*@3 s], [@(0.0.255) int] [*@3 len], [@(0.0.255) bool] +[*@3 plus`_is`_space] [@(0.0.255) `=] [@(0.0.255) true])&] +[s5;:Upp`:`:UrlDecode`(const String`&`,bool`): String [* UrlDecode]([@(0.0.255) const] +String[@(0.0.255) `&] [*@3 s], [@(0.0.255) bool] [*@3 plus`_is`_space] +[@(0.0.255) `=] [@(0.0.255) true])&] +[s2; [%% Decodes data as required by ][%%^http`:`/`/www`.w3`.org`/TR`/html401`/interact`/forms`.html`#h`-17`.13`.4`.1^ M +IME type application/x`-www`-form`-urlencoded][%% (see UrlEncode). +If ][*@3 plus`_is`_space] is false, `'`+`' is not converted to +space.&] [s3;%% &] [s4; &] [s5;:QPEncode`(const char`*`): [_^String^ String]_[* QPEncode]([@(0.0.255) const]_[@(0.0.255) c diff --git a/uppsrc/CtrlCore/GtkClip.cpp b/uppsrc/CtrlCore/GtkClip.cpp index e831eee76..2419455d7 100644 --- a/uppsrc/CtrlCore/GtkClip.cpp +++ b/uppsrc/CtrlCore/GtkClip.cpp @@ -83,10 +83,10 @@ void Ctrl::Gclipboard::Put(const String& fmt, const ClipData& data) target.GetAdd(fmt) = data; GtkTargetList *list = CreateTargetList(target); - + gint n; GtkTargetEntry *targets = gtk_target_table_new_from_list(list, &n); - + gtk_clipboard_set_with_data(clipboard, targets, n, GtkGetClipData, ClearClipData, this); gtk_clipboard_set_can_store(clipboard, NULL, 0); @@ -366,9 +366,9 @@ Vector GetClipFiles(const String& data) { Vector r; Vector f = Split(data, '\n'); - for(int i = 0; i < f.GetCount(); i++) - if(f[i].StartsWith("file://")) - r.Add(f[i].Mid(7)); + for(String s : f) + if(s.TrimStart("file://")) + r << UrlDecode(s, false); return r; } @@ -384,8 +384,8 @@ void AppendFiles(VectorMap& data, const Vector& files) if(files.GetCount() == 0) return; String h; - for(int i = 0; i < files.GetCount(); i++) - h << "file://" << files[i] << '\n'; + for(String f : files) + h << "file://" << UrlEncode(f) << '\n'; data.GetAdd("files") = h; } @@ -414,4 +414,4 @@ void Ctrl::SetSelectionSource(const char *fmts) } -#endif +#endif \ No newline at end of file