Overview
| Artifact ID: | e96f15395fb0a03dfa79a170d65b4d083c15200355ee5c00f7f18c7c301155fd |
|---|---|
| Ticket: | 5f923c60b2f8e9ccbf5702d673c25b09afb460be
URL-Encoding of invalid characters in URL |
| User & Date: | kjnash on 2018-04-13 15:08:54 |
Changes
- icomment:
There are corner cases that would make this conversion a little awkward - for example if a user has edited a URL in the address bar and added illegal characters, should the command conclude that the entire URL needs conversion and convert any existing "%" again? What if an existing "%" is not followed by a valid hexadecimal code? Should "+" be considered a valid conversion of the space character, or should it be converted to "%2B"? I wonder how the Python library resolves problems like this. The command http::geturl expects a valid URL. However, the http library could provide commands to encode a URL before passing it to http::geturl. In the meantime, if you know that the URL path needs encoding, the following code will do it: package require http package require uri proc urlEncodePath {url} { set splits [uri::split $url] set encPathList {} set path [dict get $splits path] set pathList [split $path /] foreach el $pathList { lappend encPathList [http::mapReply $el] } set path [join $encPathList /] dict set splits path $path uri::join {*}$splits } set url http://127.0.0.1:33543/hub/session/fedc2754-770e-4b3a-9c1e-2fb16d0e0eaf/element/{56dcfe8e-c512-4dbf-a37a-4dbfb6d14b98}/value urlEncodePath $url - returns - http://127.0.0.1:33543/hub/session/fedc2754-770e-4b3a-9c1e-2fb16d0e0eaf/element/%7B56dcfe8e-c512-4dbf-a37a-4dbfb6d14b98%7D/value - login: "kjnash"
- mimetype: "text/plain"