[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Gnash-commit] gnash ChangeLog libbase/URL.cpp libbase/URL.h s...
From: |
Sandro Santilli |
Subject: |
[Gnash-commit] gnash ChangeLog libbase/URL.cpp libbase/URL.h s... |
Date: |
Sun, 25 Feb 2007 18:32:00 +0000 |
CVSROOT: /sources/gnash
Module name: gnash
Changes by: Sandro Santilli <strk> 07/02/25 18:32:00
Modified files:
. : ChangeLog
libbase : URL.cpp URL.h
server/asobj : Global.cpp
Log message:
* libbase/URL.{cpp,h}: add encode() and decode()
public static functions.
* server/asobj/Global.cpp (escape/unescape):
Use URL::encode and URL::decode.
CVSWeb URLs:
http://cvs.savannah.gnu.org/viewcvs/gnash/ChangeLog?cvsroot=gnash&r1=1.2465&r2=1.2466
http://cvs.savannah.gnu.org/viewcvs/gnash/libbase/URL.cpp?cvsroot=gnash&r1=1.32&r2=1.33
http://cvs.savannah.gnu.org/viewcvs/gnash/libbase/URL.h?cvsroot=gnash&r1=1.13&r2=1.14
http://cvs.savannah.gnu.org/viewcvs/gnash/server/asobj/Global.cpp?cvsroot=gnash&r1=1.45&r2=1.46
Patches:
Index: ChangeLog
===================================================================
RCS file: /sources/gnash/gnash/ChangeLog,v
retrieving revision 1.2465
retrieving revision 1.2466
diff -u -b -r1.2465 -r1.2466
--- ChangeLog 25 Feb 2007 17:07:07 -0000 1.2465
+++ ChangeLog 25 Feb 2007 18:31:59 -0000 1.2466
@@ -1,5 +1,12 @@
2007-02-25 Sandro Santilli <address@hidden>
+ * libbase/URL.{cpp,h}: add encode() and decode()
+ public static functions.
+ * server/asobj/Global.cpp (escape/unescape):
+ Use URL::encode and URL::decode.
+
+2007-02-25 Sandro Santilli <address@hidden>
+
* server/PropertyList.{cpp,h}: add
enumerateKeyValue() method; renamed
enumerateValues to enumerateKeys (makes more sense).
Index: libbase/URL.cpp
===================================================================
RCS file: /sources/gnash/gnash/libbase/URL.cpp,v
retrieving revision 1.32
retrieving revision 1.33
diff -u -b -r1.32 -r1.33
--- libbase/URL.cpp 6 Dec 2006 10:58:34 -0000 1.32
+++ libbase/URL.cpp 25 Feb 2007 18:32:00 -0000 1.33
@@ -396,6 +396,55 @@
}
}
+/* public static */
+void
+URL::encode(std::string& input)
+{
+ const string escapees = " \"#$%&+,/:;<=>address@hidden|}~";
+ const string hexdigits = "0123456789ABCDEF";
+
+ for (unsigned int i=0;i<input.length(); i++)
+ {
+ unsigned c = input[i] & 0xFF; // ensure value is 0-255 not -ve
+
+ if (c < 32 || c > 126 || escapees.find((char)c) != string::npos)
+ {
+ input[i] = '%';
+ input.insert(++i, hexdigits.substr(c >> 4, 1));
+ input.insert(++i, hexdigits.substr(c & 0xF, 1));
+ }
+ }
+}
+
+/* public static */
+void
+URL::decode(std::string& input)
+{
+ int hexcode;
+
+ for (unsigned int i=0; i<input.length(); i++)
+ {
+ if (input[i] == '%' && (input.length() > i + 2) &&
+ isxdigit(input[i+1]) && isxdigit(input[i+2]))
+ {
+ input[i+1] = toupper(input[i+1]);
+ input[i+2] = toupper(input[i+2]);
+ if (isdigit(input[i+1]))
+ hexcode = (input[i+1] - '0') * 16;
+ else
+ hexcode = (input[i+1] - 'A' + 10) * 16;
+
+ if (isdigit(input[i+2]))
+ hexcode += (input[i+2] - '0');
+ else
+ hexcode += (input[i+2] - 'A' + 10);
+
+ input[i] = (char)hexcode;
+ input.erase(i+1, 2);
+ }
+ }
+}
+
ostream& operator<< (ostream& o, const URL& u)
{
return o << u.str();
Index: libbase/URL.h
===================================================================
RCS file: /sources/gnash/gnash/libbase/URL.h,v
retrieving revision 1.13
retrieving revision 1.14
diff -u -b -r1.13 -r1.14
--- libbase/URL.h 29 Oct 2006 18:34:11 -0000 1.13
+++ libbase/URL.h 25 Feb 2007 18:32:00 -0000 1.14
@@ -106,6 +106,40 @@
///
static void parse_querystring(const std::string& query_string,
std::map<std::string, std::string>& target_map);
+
+ /// \brief
+ /// Encode a string to URL-encoded format
+ /// converting all dodgy characters to %AB hex sequences
+ //
+ /// Characters that need escaping are:
+ /// - ASCII control characters: 0-31 and 127
+ /// - Non-ASCII chars: 128-255
+ /// - URL syntax characters: $ & + , / : ; = ? @
+ /// - Unsafe characters: SPACE " < > # % { } | \ ^ ~ [ ] `
+ /// Encoding is a % followed by two hexadecimal characters, case
insensitive.
+ /// See RFC1738 http://www.rfc-editor.org/rfc/rfc1738.txt,
+ /// Section 2.2 "URL Character Encoding Issues"
+ ///
+ ///
+ /// @param str
+ /// The input/output string
+ ///
+ static void encode(std::string& str);
+
+ /// \brief
+ /// Decode a string from URL-encoded format
+ /// converting all hexadecimal sequences to ASCII characters.
+ //
+ /// A sequence to convert is % followed by two case-independent
hexadecimal
+ /// digits, which is replaced by the equivalent ASCII character.
+ /// See RFC1738 http://www.rfc-editor.org/rfc/rfc1738.txt,
+ /// Section 2.2 "URL Character Encoding Issues"
+ ///
+ /// @param str
+ /// The input/output string
+ ///
+ static void decode(std::string& str);
+
private:
void init_absolute(const std::string& absurl);
Index: server/asobj/Global.cpp
===================================================================
RCS file: /sources/gnash/gnash/server/asobj/Global.cpp,v
retrieving revision 1.45
retrieving revision 1.46
diff -u -b -r1.45 -r1.46
--- server/asobj/Global.cpp 21 Feb 2007 20:22:59 -0000 1.45
+++ server/asobj/Global.cpp 25 Feb 2007 18:32:00 -0000 1.46
@@ -1,5 +1,5 @@
//
-// Copyright (C) 2005, 2006 Free Software Foundation, Inc.
+// Copyright (C) 2005, 2006, 2007 Free Software Foundation, Inc.
//
// This program is free software; you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
@@ -18,7 +18,7 @@
// Implementation of the Global ActionScript Object
-/* $Id: Global.cpp,v 1.45 2007/02/21 20:22:59 strk Exp $ */
+/* $Id: Global.cpp,v 1.46 2007/02/25 18:32:00 strk Exp $ */
#ifdef HAVE_CONFIG_H
#include "config.h"
@@ -61,6 +61,7 @@
#include "extension.h"
#include "VM.h"
#include "timers.h"
+#include "URL.h" // for URL::encode and URL::decode (escape/unescape)
#include "fn_call.h"
#include "sprite_instance.h"
@@ -144,16 +145,8 @@
string input = fn.arg(0).to_string();
- for (unsigned int i=0;i<input.length(); i++)
- {
- unsigned c = input[i] & 0xFF; // ensure value is 0-255 not -ve
+ URL::encode(input);
- if (c < 32 || c > 126 || escapees.find((char)c) != string::npos) {
- input[i] = '%';
- input.insert(++i, hexdigits.substr(c >> 4, 1));
- input.insert(++i, hexdigits.substr(c & 0xF, 1));
- }
- }
fn.result->set_string(input.c_str());
}
@@ -171,29 +164,7 @@
ASSERT_FN_ARGS_IS_1
string input = fn.arg(0).to_string();
- int hexcode;
-
- for (unsigned int i=0; i<input.length(); i++)
- {
- if (input[i] == '%' && (input.length() > i + 2) &&
- isxdigit(input[i+1]) && isxdigit(input[i+2]))
- {
- input[i+1] = toupper(input[i+1]);
- input[i+2] = toupper(input[i+2]);
- if (isdigit(input[i+1]))
- hexcode = (input[i+1] - '0') * 16;
- else
- hexcode = (input[i+1] - 'A' + 10) * 16;
-
- if (isdigit(input[i+2]))
- hexcode += (input[i+2] - '0');
- else
- hexcode += (input[i+2] - 'A' + 10);
-
- input[i] = (char)hexcode;
- input.erase(i+1, 2);
- }
- }
+ URL::decode(input);
fn.result->set_string(input.c_str());
}
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [Gnash-commit] gnash ChangeLog libbase/URL.cpp libbase/URL.h s...,
Sandro Santilli <=