[PEAR-BUG] Bug #20421 [Fbk]: Reject invalid path
[email protected] Wed, 8 Oct 2014 01:52:36 +0100 (BST)
| Newsgroups | php.pear.bugs |
|---|---|
| Message-ID | <[email protected]> |
Edit report at https://pear.php.net/bugs/bug.php?id=20421&edit=1 ID: 20421 Updated by: [email protected] Reported By: jan dot prachar at gmail dot com Summary: Reject invalid path Status: Feedback Type: Bug Package: Net_URL2 Package Version: 2.0.7 PHP Version: Irrelevant Assigned To: tkli Roadmap Versions: New Comment: thanks for sharing, I did overlook the setPath() call in the actual example code. however the problem still remains: if you set "//h" as path and there is no authority, Net_URL2 actually leaves that up to the user. As it starts with "//" and with no authority, this denotes "h" as the new authority and no path. not saying this is a good way to deal with it, i need to think about this a little. exception throwing is not my preferred option to solve this one. using a method with "path" in it's name to change the authority is not fine, too. as you rightfully say, this is inconsistent. Previous Comments: ------------------------------------------------------------------------ [2014-10-08 01:10:44] pracj3am At least now you are inconsistent in handling invalid path in case of present and missing authority. ------------------------------------------------------------------------ [2014-10-08 01:09:01] pracj3am My motivation was seeing this line of code: https://github.com/pear/Net_URL2/blob/master/Net/URL2.php#L728 and this bug report https://pear.php.net/bugs/bug.php?id=20159 Here you are modifying a path in order to get a valid URI. And I think that bug #20159 is not bug at all. Th query and fragment has separators (? and #), but path has not. I think you should compose URI from the parts as they were set and leave the responsiblity to user of the library (or notify him by throwing an exception). Thanks! ------------------------------------------------------------------------ [2014-10-08 00:15:22] tkli -Status: Open +Status: Feedback -Assigned To: +Assigned To: tkli what you write is correct in terms of RFC 3986 but unfortunately Net_URL2 is not about URI validation (in full or in part). therefore throwing an exception while calling Net_URL2::setPath() (or Net_URL2::getUrl() and those by yours correctly named authority counterparts) could be (at least) unexpected or just straight forward introduce a new feature. if you share more about your motivation, it might be possible to find a beautiful way to keep Net_URL2 open for extension but closed for modification offering good options for your validation needs. me seeing more context would also allow me to better understand why you qualified this as a bug. feedback welcome. -- tk ------------------------------------------------------------------------ [2014-10-03 00:01:42] pracj3am As well as when you set path first and then add/remove authority. ------------------------------------------------------------------------ [2014-10-02 23:56:49] pracj3am Description: ------------ See https://tools.ietf.org/html/rfc3986#section-3.3 Path should be empty or begin with slash if authority is present. If a URI does not contain an authority component, then the path cannot begin with two slash characters. Test script: --------------- $url = new Net_URL2('http:g'); $url->setPath('//h'); echo $url->getUrl(); Expected result: ---------------- *exception thrown* Actual result: -------------- http://h ------------------------------------------------------------------------ -- Edit this bug report at https://pear.php.net/bugs/bug.php?id=20421&edit=1