Opened 7 years ago
Closed 7 years ago
#42740 closed defect (bug) (fixed)
Relative Links in Image Widget
Reported by: | kcrnc | Owned by: | westonruter |
---|---|---|---|
Milestone: | 4.9.3 | Priority: | normal |
Severity: | normal | Version: | 4.9 |
Component: | Widgets | Keywords: | has-patch commit fixed-major |
Focuses: | Cc: |
Description
When using the image widget and adding a custom URL, I noticed that relative links are not supported.
Adding a relative link to the widget result in an error being shown(red highlighted box) and then the widget doesn't save.
I think this may be a feature not a bug, but I can think of a few times when you might want to be able to put a link there without including the 'http' or 'https.'
Like if you want to add an anchor instead of a link, like #some_div
or if you want the link to work regardless of whether HTTP or HTTPS is being used.
Attachments (3)
Change History (22)
#1
in reply to:
↑ description
@
7 years ago
#2
@
7 years ago
- Keywords needs-patch added
- Milestone changed from Awaiting Review to 4.9.2
Good observation. It's because we're using an HTML5 url
field here. We should change it to allow for partial URLs. We can incorporate the same logic as done in #42506.
#3
@
7 years ago
- Keywords has-patch added; needs-patch removed
EDIT: Ok didn't saw @westonruter previous answer, but I guess my small patch is still relevant as it seems to be the same observation.
Hi @kcrnc
I reproduced your issue. It's due to the url
html5 field.
Here is a (very) small patch, transforming url
input into text
input. We don't need url field, I guess, as other link fields already uses text
field as well in WP core.
I tested it and it's fine with this patch.
Cheers,
Jb
#4
@
7 years ago
This ticket was mentioned in Slack in #core by audrasjb. View the logs.
7 years ago
This ticket was mentioned in Slack in #core-customize by westonruter. View the logs.
7 years ago
#7
@
7 years ago
The regular expression from [42154] could just be added as a pattern
attribute for the input that you changed from url
to text
.
#9
@
7 years ago
In particular, the value of the pattern
attribute I think should be:
((\w+:)?\/\/\w.*|\w+:(?!\/\/$)|\/|\?|#).*
#10
@
7 years ago
- Keywords has-patch added; needs-patch removed
Wow. Thanks @westonruter for this great hint!
I used the pattern found in this file.
This ticket was mentioned in Slack in #core by audrasjb. View the logs.
7 years ago
#13
@
7 years ago
Terminology notes:
"relative vs absolute"
URLs without the protocol part or without the domain name are still "absolute" if they don't depend on the context, for example:
/somepath/somefile
//mysite.com/somepath/somefile
are absolute URLs
Only URLs that depend on context, i.e. the location of the document they're used into, are "relative" for example:
somepath/somefile
../somefile
#14
@
7 years ago
@afercia
I believe it is a fairly common usage.
It wouldn't be relative on a file system, but is relative to the URL or protocol.
Googling 'relative vs absolute paths' and 'relative vs absolute urls' provides various definitions supporting both uses.
#15
@
7 years ago
@kcrnc I wouldn't recommend Googling :) Instead, I'd recommend specifications or authoritative sources:
https://developer.mozilla.org/en-US/docs/Learn/Common_questions/What_is_a_URL
I know it's common usage, but it's just a common mistake.
#16
@
7 years ago
@afercia
'google' or a search engine, is a good starting point for finding authoritative sources and you can find plenty to support both.
While I like mozilla a lot, the source you provided is user edited and I don't see any sources on that page.
Here is an article from google using the alternate syntax: https://support.google.com/analytics/answer/2664470?hl=en
Here is a memo from 1995 that describes the alternate use as well: https://tools.ietf.org/html/rfc1808
"The syntax for relative URLs is a shortened form of that for absolute URLs [2], where some prefix of the URL is missing and certain path components ("." and "..") have a special meaning"
The scheme is described later on in the spec and this is referenced here: https://tools.ietf.org/html/rfc2616
#17
@
7 years ago
- Owner set to westonruter
- Resolution set to fixed
- Status changed from new to closed
In 42533:
So, for example:
Working: https://core.trac.wordpress.org/ticket/42740
Not Working: /ticket/42740
Not Working: #header_nav