Opened 2 years ago
Last modified 3 months ago
#16859 accepted defect (bug)
esc_url eats square brackets.
| Reported by: |
|
Owned by: |
|
|---|---|---|---|
| Priority: | normal | Milestone: | Awaiting Review |
| Component: | Formatting | Version: | 3.1 |
| Severity: | minor | Keywords: | has-patch dev-feedback |
| Cc: | ldebrouwer |
Description (last modified by westi)
When adding a link to the blogroll (using wp-admin/link-add.php), square brackets in the link are removed, breaking the link.
Example:
http://lokale-wochenzeitungen.de/index.php?id=485&tx_ttnews[pointer]=6&tx_ttnews[tt_news]=132583&tx_ttnews[backPid]=741&cHash=ee9c87874b
becomes
http://lokale-wochenzeitungen.de/index.php?id=485&tx_ttnewspointer=6&tx_ttnewstt_news=132583&tx_ttnewsbackPid=741&cHash=ee9c87874b
Workaround: Use URL-encoded links (%5B and %5D instead of [ and ]).
This also affects urls which are made clickable by {{{make_clickable}}
Attachments (3)
Change History (22)
comment:1
follow-up:
↓ 2
ldebrouwer — 2 years ago
- Cc ldebrouwer added
- Keywords 2nd-opinion added; needs-patch removed
Replying to ldebrouwer:
To achieve this we would need to alter esc_url which I'm pretty sure is not going to happen because URLs containing brackets shouldn't be floating around and should always be encoded!
Is it possible to wrap a urlencode() around the URL before escaping it? Didn't have a look at the code yet, so don't know if that makes sense.
If you take a look at the URL spec ( http://www.w3.org/Addressing/URL/url-spec.txt ) you can read:
[...]
True (wasn't aware of that, thanks).
However, the PHP FAQ suggests using square brackets for form fields to create arrays ( http://www.php.net/manual/en/faq.html.php#faq.html.arrays ). Also, a similar problem came up in ticket:12690, so I thought it might be interesting.
I don't know if you've copied the URL from somewhere but the brackets definitely shouldn't be there.
The URL is generated by the (IMHO popular) tt_news extension for Typo3.
However, the PHP FAQ suggests using square brackets for form fields to create arrays
That's correct, however, it doesnt mean that the characters should be unescaped in a GET request.
Replying to dd32:
However, the PHP FAQ suggests using square brackets for form fields to create arrays
That's correct, however, it doesnt mean that the characters should be unescaped in a GET request.
Yah, but apparently it happens when copy-pasting a URL from the address bar or using 'copy link location'.
comment:5
in reply to:
↑ 4
ldebrouwer — 2 years ago
Replying to f00f:
Yah, but apparently it happens when copy-pasting a URL from the address bar or using 'copy link location'.
And that, to me, seems the root of the problem. You copy a, according to standards, malformed URL from a third-party. And WordPress, as a service, filters all the bad characters from the URL for security reasons. To me WordPress should not anticipate specific behaviour of third-party software ( browsers aside ), just the behaviour of the users.
I hear you. Well, hopefully this ticket helps someone experiencing the same problem I did.
Just looking at this, [] should definitely be allowed in the url's.. at least in the query segment
comment:8
ldebrouwer — 2 years ago
No they shouldn't, at least not unencoded. And like I pointed out earlier it's not up to WordPress to fix the problems of third-parties.
No they shouldn't, at least not unencoded.
In URL's produced, sure.
However, users should not be expected to encode the values themselves, many links/sites do not encode them themselves, which leads to this case of users encountering issues when pasting the links in.
[] should be allowed to be entered, they shouldn't be striped, perhaps they should be encoded or similar however.
comment:10
edwardw — 22 months ago
- Keywords has-patch dev-feedback added; 2nd-opinion removed
- Owner set to edwardw
- Status changed from new to accepted
Even though brackets should be encoded for use in third-party applications in theory, we should not blame the user who often may not even be aware of this. Often the URL is copied from the location bar or other source where they have not encoded this, and especially due to PHP's use of brackets to pass arrays. I have attached a patch which urlencode()s brackets when cleaning URLs.
comment:11
westi — 22 months ago
- Keywords needs-patch added; has-patch dev-feedback removed
I'm not sure we should be patching esc_url for this issue but rather just fix the link add/editing work flow to correctly encode the square brackets.
[PATCH] Urlencode brackets when cleaning, patching wp-admin/bookmark.php instead
comment:12
edwardw — 22 months ago
- Keywords has-patch dev-feedback added; needs-patch removed
Agreed.
comment:13
westi — 12 months ago
- Description modified (diff)
- Owner changed from edwardw to westi
- Summary changed from Square brackets are removed from links in blogroll to esc_url eats square brackets.
I've changed my mind about this as it affects a number of places and I think we do better to patch esc_url to fix this for [] by encoding them for you.
comment:14
nacin — 12 months ago
Per RFC 1738, brackets are considered "unsafe", and are not reserved, and should therefore always be encoded. http://tools.ietf.org/html/rfc1738#section-2.2
But per RFC3986, they are now a reserved gen-delimiter character, which means it would not be in our best interest to blindly encode all of the ones we find: http://tools.ietf.org/html/rfc3986#section-2.2. It is designed for wrapping an IPv6+ address for the host, according to http://tools.ietf.org/html/rfc3986#section-3.2.2. This is actually okay, as we can pretty easily avoid targeting the host. That it is a reserved character with a specific meaning allows us to make this change in a more future-proof way.
comment:15
westi — 12 months ago
Simple make_clickable tests in [UT725]
comment:16
westi — 12 months ago
Simple esc_url tests in [UT726] which include IPv6 url tests.
Simple fix to just encode square brackets in esc_url - breaks IPv6 urls though.
comment:17
nacin — 6 months ago
esc_url() can also eat unencoded colons: #21974.
comment:18
SergeyBiryukov — 4 months ago
- Component changed from General to Formatting
comment:19
SergeyBiryukov — 3 months ago
#23519 was marked as a duplicate.

To achieve this we would need to alter esc_url which I'm pretty sure is not going to happen because URLs containing brackets shouldn't be floating around and should always be encoded!
If you take a look at the URL spec ( http://www.w3.org/Addressing/URL/url-spec.txt ) you can read:
"The 'national' and 'punctuation' characters do not appear in any productions and therefore may not appear in URLs.
national { | } | vline | [ | ] | \ | | ~
punctuation < | >"
I don't know if you've copied the URL from somewhere but the brackets definitely shouldn't be there.