[vlc-devel] [PATCH] gui:Percent encode all URL unsafe characters

Jan Scheers jan.scheers at gmail.com
Thu Dec 22 14:00:00 CET 2011


This should fix #3435.
I wanted to reply to the previous thread but I don't know how that works in mailing lists. 

---
 modules/gui/macosx/open.m                  |    2 ++
 modules/gui/qt4/components/open_panels.cpp |   18 ++----------------
 modules/gui/qt4/components/open_panels.hpp |    9 ---------
 3 files changed, 4 insertions(+), 25 deletions(-)

diff --git a/modules/gui/macosx/open.m b/modules/gui/macosx/open.m
index 5c5fb0c..48c3d2d 100644
--- a/modules/gui/macosx/open.m
+++ b/modules/gui/macosx/open.m
@@ -1040,6 +1040,8 @@ static VLCOpen *_o_sharedMainInstance = nil;
     else
     {
         o_mrl_string = [o_net_http_url stringValue];
+        o_mrl_string = [o_mrl_string stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding];
+        o_mrl_string = [o_mrl_string stringByReplacingOccurrencesOfString:@"%25" withString:@"%"];
     }
     [self setMRL: o_mrl_string];
 }
diff --git a/modules/gui/qt4/components/open_panels.cpp b/modules/gui/qt4/components/open_panels.cpp
index 78bb4b7..c1f06d9 100644
--- a/modules/gui/qt4/components/open_panels.cpp
+++ b/modules/gui/qt4/components/open_panels.cpp
@@ -601,8 +601,6 @@ NetOpenPanel::NetOpenPanel( QWidget *_parent, intf_thread_t *_p_intf ) :
     else
         b_recentList = false;
 
-    /* Use a simple validator for URLs */
-    ui.urlComboBox->setValidator( new UrlValidator( this ) );
     ui.urlComboBox->setFocus();
 }
 
@@ -642,6 +640,8 @@ void NetOpenPanel::updateMRL()
 {
     QString url = ui.urlComboBox->lineEdit()->text();
 
+    url = QString::fromAscii( QUrl::toPercentEncoding( url, "$&+,/:;=?@%", "" ) );
+
     if( url.isEmpty() )
         return;
 
@@ -652,20 +652,6 @@ void NetOpenPanel::updateMRL()
     emit mrlUpdated( qsl, "" );
 }
 
-QValidator::State UrlValidator::validate( QString& str, int& ) const
-{
-    if( str.contains( ' ' ) )
-        return QValidator::Invalid;
-    if( !str.contains( "://" ) )
-        return QValidator::Intermediate;
-    return QValidator::Acceptable;
-}
-
-void UrlValidator::fixup( QString& str ) const
-{
-    str = str.trimmed();
-}
-
 /**************************************************************************
  * Open Capture device ( DVB, PVR, V4L, and similar )                     *
  **************************************************************************/
diff --git a/modules/gui/qt4/components/open_panels.hpp b/modules/gui/qt4/components/open_panels.hpp
index 85257ce..0f7c216 100644
--- a/modules/gui/qt4/components/open_panels.hpp
+++ b/modules/gui/qt4/components/open_panels.hpp
@@ -149,15 +149,6 @@ public slots:
     virtual void updateMRL();
 };
 
-class UrlValidator : public QValidator
-{
-   Q_OBJECT
-public:
-   UrlValidator( QObject *parent ) : QValidator( parent ) { }
-   void fixup( QString& ) const;
-   QValidator::State validate( QString&, int& ) const;
-};
-
 class DiscOpenPanel: public OpenPanel
 {
     Q_OBJECT
-- 
1.7.8




More information about the vlc-devel mailing list