Extend valid_url()

c960657 - August 13, 2008 - 21:53
Project:Drupal
Version:7.x-dev
Component:base system
Category:bug report
Priority:normal
Assigned:Unassigned
Status:needs work
Issue tags:IDN
Description

valid_url() only does some very simple syntex checks to verify whether the URL is valid and thus accepts some malformed URLs. Still it does not allow all valid URLs (see e.g. #124492: valid_url() does not support all valid URL characters).

Only certain URL schemes are accepted (http, https and ftp), though other schemes may be relevant in various use cases (like this: #214516: Add RTSP to default list of allowed protocols).

I tried to expand the function with a number of checks controlled by options.

What do you think - is this totally overkill, or is it worth exploring? The code is still work in progress.

AttachmentSizeStatusTest resultOperations
url.txt5.74 KBIgnoredNoneNone

#1

grndlvl - August 29, 2008 - 21:42

created test for valid_url() used your proposed function for testing, function has some errors.

Here are my test results and the patch for the test is included.

Message Group Filename Line Function Status
ftp://example.com is a valid url. Other drupal_web_test_case.php 284 testValidUrl
http://example.com is a valid url. Other drupal_web_test_case.php 284 testValidUrl
https://example.com is a valid url. Other drupal_web_test_case.php 284 testValidUrl
irc://example.com is a valid url. Other drupal_web_test_case.php 284 testValidUrl
mailto://example.com is a valid url. Other drupal_web_test_case.php 284 testValidUrl
news://example.com is a valid url. Other drupal_web_test_case.php 284 testValidUrl
nntp://example.com is a valid url. Other drupal_web_test_case.php 284 testValidUrl
rtsp://example.com is a valid url. Other drupal_web_test_case.php 284 testValidUrl
sftp://example.com is a valid url. Other drupal_web_test_case.php 284 testValidUrl
ssh://example.com is a valid url. Other drupal_web_test_case.php 284 testValidUrl
telnet://example.com is a valid url. Other drupal_web_test_case.php 284 testValidUrl
webcal://example.com is a valid url. Other drupal_web_test_case.php 284 testValidUrl
example.com is a valid url. Other drupal_web_test_case.php 284 testValidUrl
ftp://www.example.com is a valid url. Other drupal_web_test_case.php 284 testValidUrl
http://www.example.com is a valid url. Other drupal_web_test_case.php 284 testValidUrl
https://www.example.com is a valid url. Other drupal_web_test_case.php 284 testValidUrl
irc://www.example.com is a valid url. Other drupal_web_test_case.php 284 testValidUrl
mailto://www.example.com is a valid url. Other drupal_web_test_case.php 284 testValidUrl
news://www.example.com is a valid url. Other drupal_web_test_case.php 284 testValidUrl
nntp://www.example.com is a valid url. Other drupal_web_test_case.php 284 testValidUrl
rtsp://www.example.com is a valid url. Other drupal_web_test_case.php 284 testValidUrl
sftp://www.example.com is a valid url. Other drupal_web_test_case.php 284 testValidUrl
ssh://www.example.com is a valid url. Other drupal_web_test_case.php 284 testValidUrl
telnet://www.example.com is a valid url. Other drupal_web_test_case.php 284 testValidUrl
webcal://www.example.com is a valid url. Other drupal_web_test_case.php 284 testValidUrl
www.example.com is a valid url. Other drupal_web_test_case.php 284 testValidUrl
ftp://ex-ample.com is a valid url. Other drupal_web_test_case.php 284 testValidUrl
http://ex-ample.com is a valid url. Other drupal_web_test_case.php 284 testValidUrl
https://ex-ample.com is a valid url. Other drupal_web_test_case.php 284 testValidUrl
irc://ex-ample.com is a valid url. Other drupal_web_test_case.php 284 testValidUrl
mailto://ex-ample.com is a valid url. Other drupal_web_test_case.php 284 testValidUrl
news://ex-ample.com is a valid url. Other drupal_web_test_case.php 284 testValidUrl
nntp://ex-ample.com is a valid url. Other drupal_web_test_case.php 284 testValidUrl
rtsp://ex-ample.com is a valid url. Other drupal_web_test_case.php 284 testValidUrl
sftp://ex-ample.com is a valid url. Other drupal_web_test_case.php 284 testValidUrl
ssh://ex-ample.com is a valid url. Other drupal_web_test_case.php 284 testValidUrl
telnet://ex-ample.com is a valid url. Other drupal_web_test_case.php 284 testValidUrl
webcal://ex-ample.com is a valid url. Other drupal_web_test_case.php 284 testValidUrl
ex-ample.com is a valid url. Other drupal_web_test_case.php 284 testValidUrl
ftp://3xampl3.com is a valid url. Other drupal_web_test_case.php 284 testValidUrl
http://3xampl3.com is a valid url. Other drupal_web_test_case.php 284 testValidUrl
https://3xampl3.com is a valid url. Other drupal_web_test_case.php 284 testValidUrl
irc://3xampl3.com is a valid url. Other drupal_web_test_case.php 284 testValidUrl
mailto://3xampl3.com is a valid url. Other drupal_web_test_case.php 284 testValidUrl
news://3xampl3.com is a valid url. Other drupal_web_test_case.php 284 testValidUrl
nntp://3xampl3.com is a valid url. Other drupal_web_test_case.php 284 testValidUrl
rtsp://3xampl3.com is a valid url. Other drupal_web_test_case.php 284 testValidUrl
sftp://3xampl3.com is a valid url. Other drupal_web_test_case.php 284 testValidUrl
ssh://3xampl3.com is a valid url. Other drupal_web_test_case.php 284 testValidUrl
telnet://3xampl3.com is a valid url. Other drupal_web_test_case.php 284 testValidUrl
webcal://3xampl3.com is a valid url. Other drupal_web_test_case.php 284 testValidUrl
3xampl3.com is a valid url. Other drupal_web_test_case.php 284 testValidUrl
ftp://example.com/paren(the)sis is a valid url. Other drupal_web_test_case.php 284 testValidUrl
http://example.com/paren(the)sis is a valid url. Other drupal_web_test_case.php 284 testValidUrl
https://example.com/paren(the)sis is a valid url. Other drupal_web_test_case.php 284 testValidUrl
irc://example.com/paren(the)sis is a valid url. Other drupal_web_test_case.php 284 testValidUrl
mailto://example.com/paren(the)sis is a valid url. Other drupal_web_test_case.php 284 testValidUrl
news://example.com/paren(the)sis is a valid url. Other drupal_web_test_case.php 284 testValidUrl
nntp://example.com/paren(the)sis is a valid url. Other drupal_web_test_case.php 284 testValidUrl
rtsp://example.com/paren(the)sis is a valid url. Other drupal_web_test_case.php 284 testValidUrl
sftp://example.com/paren(the)sis is a valid url. Other drupal_web_test_case.php 284 testValidUrl
ssh://example.com/paren(the)sis is a valid url. Other drupal_web_test_case.php 284 testValidUrl
telnet://example.com/paren(the)sis is a valid url. Other drupal_web_test_case.php 284 testValidUrl
webcal://example.com/paren(the)sis is a valid url. Other drupal_web_test_case.php 284 testValidUrl
example.com/paren(the)sis is a valid url. Other drupal_web_test_case.php 284 testValidUrl
ftp://example.com/index.html#pagetop is a valid url. Other drupal_web_test_case.php 284 testValidUrl
http://example.com/index.html#pagetop is a valid url. Other drupal_web_test_case.php 284 testValidUrl
https://example.com/index.html#pagetop is a valid url. Other drupal_web_test_case.php 284 testValidUrl
irc://example.com/index.html#pagetop is a valid url. Other drupal_web_test_case.php 284 testValidUrl
mailto://example.com/index.html#pagetop is a valid url. Other drupal_web_test_case.php 284 testValidUrl
news://example.com/index.html#pagetop is a valid url. Other drupal_web_test_case.php 284 testValidUrl
nntp://example.com/index.html#pagetop is a valid url. Other drupal_web_test_case.php 284 testValidUrl
rtsp://example.com/index.html#pagetop is a valid url. Other drupal_web_test_case.php 284 testValidUrl
sftp://example.com/index.html#pagetop is a valid url. Other drupal_web_test_case.php 284 testValidUrl
ssh://example.com/index.html#pagetop is a valid url. Other drupal_web_test_case.php 284 testValidUrl
telnet://example.com/index.html#pagetop is a valid url. Other drupal_web_test_case.php 284 testValidUrl
webcal://example.com/index.html#pagetop is a valid url. Other drupal_web_test_case.php 284 testValidUrl
example.com/index.html#pagetop is a valid url. Other drupal_web_test_case.php 284 testValidUrl
ftp://example.com:8080 is a valid url. Other drupal_web_test_case.php 284 testValidUrl
http://example.com:8080 is a valid url. Other drupal_web_test_case.php 284 testValidUrl
https://example.com:8080 is a valid url. Other drupal_web_test_case.php 284 testValidUrl
irc://example.com:8080 is a valid url. Other drupal_web_test_case.php 284 testValidUrl
mailto://example.com:8080 is a valid url. Other drupal_web_test_case.php 284 testValidUrl
news://example.com:8080 is a valid url. Other drupal_web_test_case.php 284 testValidUrl
nntp://example.com:8080 is a valid url. Other drupal_web_test_case.php 284 testValidUrl
rtsp://example.com:8080 is a valid url. Other drupal_web_test_case.php 284 testValidUrl
sftp://example.com:8080 is a valid url. Other drupal_web_test_case.php 284 testValidUrl
ssh://example.com:8080 is a valid url. Other drupal_web_test_case.php 284 testValidUrl
telnet://example.com:8080 is a valid url. Other drupal_web_test_case.php 284 testValidUrl
webcal://example.com:8080 is a valid url. Other drupal_web_test_case.php 284 testValidUrl
example.com:8080 is a valid url. Other drupal_web_test_case.php 284 testValidUrl
ftp://sudomain.example.com is a valid url. Other drupal_web_test_case.php 284 testValidUrl
http://sudomain.example.com is a valid url. Other drupal_web_test_case.php 284 testValidUrl
https://sudomain.example.com is a valid url. Other drupal_web_test_case.php 284 testValidUrl
irc://sudomain.example.com is a valid url. Other drupal_web_test_case.php 284 testValidUrl
mailto://sudomain.example.com is a valid url. Other drupal_web_test_case.php 284 testValidUrl
news://sudomain.example.com is a valid url. Other drupal_web_test_case.php 284 testValidUrl
nntp://sudomain.example.com is a valid url. Other drupal_web_test_case.php 284 testValidUrl
rtsp://sudomain.example.com is a valid url. Other drupal_web_test_case.php 284 testValidUrl
sftp://sudomain.example.com is a valid url. Other drupal_web_test_case.php 284 testValidUrl
ssh://sudomain.example.com is a valid url. Other drupal_web_test_case.php 284 testValidUrl
telnet://sudomain.example.com is a valid url. Other drupal_web_test_case.php 284 testValidUrl
webcal://sudomain.example.com is a valid url. Other drupal_web_test_case.php 284 testValidUrl
sudomain.example.com is a valid url. Other drupal_web_test_case.php 284 testValidUrl
ftp://example.com/index.php?q=node is a valid url. Other drupal_web_test_case.php 284 testValidUrl
http://example.com/index.php?q=node is a valid url. Other drupal_web_test_case.php 284 testValidUrl
https://example.com/index.php?q=node is a valid url. Other drupal_web_test_case.php 284 testValidUrl
irc://example.com/index.php?q=node is a valid url. Other drupal_web_test_case.php 284 testValidUrl
mailto://example.com/index.php?q=node is a valid url. Other drupal_web_test_case.php 284 testValidUrl
news://example.com/index.php?q=node is a valid url. Other drupal_web_test_case.php 284 testValidUrl
nntp://example.com/index.php?q=node is a valid url. Other drupal_web_test_case.php 284 testValidUrl
rtsp://example.com/index.php?q=node is a valid url. Other drupal_web_test_case.php 284 testValidUrl
sftp://example.com/index.php?q=node is a valid url. Other drupal_web_test_case.php 284 testValidUrl
ssh://example.com/index.php?q=node is a valid url. Other drupal_web_test_case.php 284 testValidUrl
telnet://example.com/index.php?q=node is a valid url. Other drupal_web_test_case.php 284 testValidUrl
webcal://example.com/index.php?q=node is a valid url. Other drupal_web_test_case.php 284 testValidUrl
example.com/index.php?q=node is a valid url. Other drupal_web_test_case.php 284 testValidUrl
ftp://example.com/index.php?q=node&param=false is a valid url. Other drupal_web_test_case.php 284 testValidUrl
http://example.com/index.php?q=node&param=false is a valid url. Other drupal_web_test_case.php 284 testValidUrl
https://example.com/index.php?q=node&param=false is a valid url. Other drupal_web_test_case.php 284 testValidUrl
irc://example.com/index.php?q=node&param=false is a valid url. Other drupal_web_test_case.php 284 testValidUrl
mailto://example.com/index.php?q=node&param=false is a valid url. Other drupal_web_test_case.php 284 testValidUrl
news://example.com/index.php?q=node&param=false is a valid url. Other drupal_web_test_case.php 284 testValidUrl
nntp://example.com/index.php?q=node&param=false is a valid url. Other drupal_web_test_case.php 284 testValidUrl
rtsp://example.com/index.php?q=node&param=false is a valid url. Other drupal_web_test_case.php 284 testValidUrl
sftp://example.com/index.php?q=node&param=false is a valid url. Other drupal_web_test_case.php 284 testValidUrl
ssh://example.com/index.php?q=node&param=false is a valid url. Other drupal_web_test_case.php 284 testValidUrl
telnet://example.com/index.php?q=node&param=false is a valid url. Other drupal_web_test_case.php 284 testValidUrl
webcal://example.com/index.php?q=node&param=false is a valid url. Other drupal_web_test_case.php 284 testValidUrl
example.com/index.php?q=node&param=false is a valid url. Other drupal_web_test_case.php 284 testValidUrl
ftp://user@www.example.com is a valid url. Other drupal_web_test_case.php 284 testValidUrl
http://user@www.example.com is a valid url. Other drupal_web_test_case.php 284 testValidUrl
https://user@www.example.com is a valid url. Other drupal_web_test_case.php 284 testValidUrl
irc://user@www.example.com is a valid url. Other drupal_web_test_case.php 284 testValidUrl
mailto://user@www.example.com is a valid url. Other drupal_web_test_case.php 284 testValidUrl
news://user@www.example.com is a valid url. Other drupal_web_test_case.php 284 testValidUrl
nntp://user@www.example.com is a valid url. Other drupal_web_test_case.php 284 testValidUrl
rtsp://user@www.example.com is a valid url. Other drupal_web_test_case.php 284 testValidUrl
sftp://user@www.example.com is a valid url. Other drupal_web_test_case.php 284 testValidUrl
ssh://user@www.example.com is a valid url. Other drupal_web_test_case.php 284 testValidUrl
telnet://user@www.example.com is a valid url. Other drupal_web_test_case.php 284 testValidUrl
webcal://user@www.example.com is a valid url. Other drupal_web_test_case.php 284 testValidUrl
user@www.example.com is a valid url. Other drupal_web_test_case.php 284 testValidUrl
ftp://user:pass@www.example.com:8080/login.php?do=login&style=%23#pagetop is a valid url. Other drupal_web_test_case.php 284 testValidUrl
http://user:pass@www.example.com:8080/login.php?do=login&style=%23#pagetop is a valid url. Other drupal_web_test_case.php 284 testValidUrl
https://user:pass@www.example.com:8080/login.php?do=login&style=%23#pagetop is a valid url. Other drupal_web_test_case.php 284 testValidUrl
irc://user:pass@www.example.com:8080/login.php?do=login&style=%23#pagetop is a valid url. Other drupal_web_test_case.php 284 testValidUrl
mailto://user:pass@www.example.com:8080/login.php?do=login&style=%23#pagetop is a valid url. Other drupal_web_test_case.php 284 testValidUrl
news://user:pass@www.example.com:8080/login.php?do=login&style=%23#pagetop is a valid url. Other drupal_web_test_case.php 284 testValidUrl
nntp://user:pass@www.example.com:8080/login.php?do=login&style=%23#pagetop is a valid url. Other drupal_web_test_case.php 284 testValidUrl
rtsp://user:pass@www.example.com:8080/login.php?do=login&style=%23#pagetop is a valid url. Other drupal_web_test_case.php 284 testValidUrl
sftp://user:pass@www.example.com:8080/login.php?do=login&style=%23#pagetop is a valid url. Other drupal_web_test_case.php 284 testValidUrl
ssh://user:pass@www.example.com:8080/login.php?do=login&style=%23#pagetop is a valid url. Other drupal_web_test_case.php 284 testValidUrl
telnet://user:pass@www.example.com:8080/login.php?do=login&style=%23#pagetop is a valid url. Other drupal_web_test_case.php 284 testValidUrl
webcal://user:pass@www.example.com:8080/login.php?do=login&style=%23#pagetop is a valid url. Other drupal_web_test_case.php 284 testValidUrl
user:pass@www.example.com:8080/login.php?do=login&style=%23#pagetop is a valid url. Other drupal_web_test_case.php 284 testValidUrl
ftp:// is NOT a valid url. Other drupal_web_test_case.php 284 testValidUrl
http:// is NOT a valid url. Other drupal_web_test_case.php 284 testValidUrl
https:// is NOT a valid url. Other drupal_web_test_case.php 284 testValidUrl
irc:// is NOT a valid url. Other drupal_web_test_case.php 284 testValidUrl
mailto:// is NOT a valid url. Other drupal_web_test_case.php 284 testValidUrl
news:// is NOT a valid url. Other drupal_web_test_case.php 284 testValidUrl
nntp:// is NOT a valid url. Other drupal_web_test_case.php 284 testValidUrl
rtsp:// is NOT a valid url. Other drupal_web_test_case.php 284 testValidUrl
sftp:// is NOT a valid url. Other drupal_web_test_case.php 284 testValidUrl
ssh:// is NOT a valid url. Other drupal_web_test_case.php 284 testValidUrl
telnet:// is NOT a valid url. Other drupal_web_test_case.php 284 testValidUrl
webcal:// is NOT a valid url. Other drupal_web_test_case.php 284 testValidUrl
is NOT a valid url. Other drupal_web_test_case.php 284 testValidUrl
ftp://ex_ample.com is NOT a valid url. Other drupal_web_test_case.php 284 testValidUrl
http://ex_ample.com is NOT a valid url. Other drupal_web_test_case.php 284 testValidUrl
https://ex_ample.com is NOT a valid url. Other drupal_web_test_case.php 284 testValidUrl
irc://ex_ample.com is NOT a valid url. Other drupal_web_test_case.php 284 testValidUrl
mailto://ex_ample.com is NOT a valid url. Other drupal_web_test_case.php 284 testValidUrl
news://ex_ample.com is NOT a valid url. Other drupal_web_test_case.php 284 testValidUrl
nntp://ex_ample.com is NOT a valid url. Other drupal_web_test_case.php 284 testValidUrl
rtsp://ex_ample.com is NOT a valid url. Other drupal_web_test_case.php 284 testValidUrl
sftp://ex_ample.com is NOT a valid url. Other drupal_web_test_case.php 284 testValidUrl
ssh://ex_ample.com is NOT a valid url. Other drupal_web_test_case.php 284 testValidUrl
telnet://ex_ample.com is NOT a valid url. Other drupal_web_test_case.php 284 testValidUrl
webcal://ex_ample.com is NOT a valid url. Other drupal_web_test_case.php 284 testValidUrl
ex_ample.com is NOT a valid url. Other drupal_web_test_case.php 284 testValidUrl
ftp://example is NOT a valid url. Other drupal_web_test_case.php 284 testValidUrl
http://example is NOT a valid url. Other drupal_web_test_case.php 284 testValidUrl
https://example is NOT a valid url. Other drupal_web_test_case.php 284 testValidUrl
irc://example is NOT a valid url. Other drupal_web_test_case.php 284 testValidUrl
mailto://example is NOT a valid url. Other drupal_web_test_case.php 284 testValidUrl
news://example is NOT a valid url. Other drupal_web_test_case.php 284 testValidUrl
nntp://example is NOT a valid url. Other drupal_web_test_case.php 284 testValidUrl
rtsp://example is NOT a valid url. Other drupal_web_test_case.php 284 testValidUrl
sftp://example is NOT a valid url. Other drupal_web_test_case.php 284 testValidUrl
ssh://example is NOT a valid url. Other drupal_web_test_case.php 284 testValidUrl
telnet://example is NOT a valid url. Other drupal_web_test_case.php 284 testValidUrl
webcal://example is NOT a valid url. Other drupal_web_test_case.php 284 testValidUrl
example is NOT a valid url. Other drupal_web_test_case.php 284 testValidUrl
AttachmentSizeStatusTest resultOperations
testValidUrl.patch2.98 KBIgnoredNoneNone

#2

grndlvl - August 30, 2008 - 06:08

test patch will not work with this function, made alterations after creating the patch to work with mentioned function, will roll different patch that works with the following function tomorrow.

** Note this message does not affect the test results show.

AttachmentSizeStatusTest resultOperations
testValidUrl.2.patch3.05 KBIgnoredNoneNone

#3

NancyDru - August 30, 2008 - 19:02
Category:feature request» bug report
Priority:minor» normal

Invalid URL checking is not a feature - it's a bug. My users have reported that carets (^) do not work. Indeed they are not checked for in 5.x, 6.x, or 7.x. I have trouble reading "preg" patterns so I can't tell if your proposed patch fixes this.

Since this is causing "valid_url()" to fail, I'm changing this to a bug and hope it gets not only committed to 7, but all the way back to 5.

Here's one to add to your test:

http://thoth.lib.ucalgary.ca/uhtbin/cgisirsi/0/X/0/57/5/3?searchdata1=^C2671933&searchfield1=GENERAL^SUBJECT^GENERAL^^&user_id=WEBSERVER

#4

NancyDru - August 30, 2008 - 19:10

I just checked, your patch does not include the caret.

  if (preg_match('`[^a-z0-9\-._~%^!$&\'()*+,;=/?:@[\]]`i', $$part, $reg)) {

#5

NancyDru - September 1, 2008 - 00:47

The patch (with the caret fix) is now incorporated into the Web Links module and seems to work fine.

May I suggest some way of taking a boolean also for the second param so that it doesn't change the current API?

#6

Damien Tournoud - September 1, 2008 - 07:02

@NancyDru: RFC1738 tells us that:

Thus, only alphanumerics, the special characters "$-_.+!*'(),", and
reserved characters used for their reserved purposes may be used
unencoded within a URL.

The caret symbol is not one of them and shouldn't appear in an URL unencoded.

#7

NancyDru - September 1, 2008 - 13:18

The example I gave above is from an actual issue in the Web Links queue. It is created from a large and active web site. Do you wish to inform them that their web site is invalid?

BTW, valid_url, in its present form, also fails when then caret is encoded.

#8

NancyDru - September 1, 2008 - 13:33

So, I went back and removed the caret that I added and tested, and this patch appears to have a debugging lone left in, because it showed above the heading a var_dump type line: array(1) { [0]=>  string(1) "^" }

When I add a drupal_urlencode() before valid_url, I get

http%3A/%252Fthoth.lib.ucalgary.ca/uhtbin/cgisirsi/0/X/0/57/5/3%3Fsearchdata1%3D%5EC2671933%2526searchfield1%3DGENERAL%5ESUBJECT%5EGENERAL%5E%5E%2526user_id%3DWEBSERVER

which still fails to validate.

#9

NancyDru - September 2, 2008 - 19:39

Just to let you know that function valid_url($url, array $options = array()) { causes a WSOD in PHP 5.2.6.

#10

flickerfly - January 8, 2009 - 19:07

For those who see the bug side of this, you may want to watch: http://drupal.org/node/124492 . mfer has come up with a fix that is getting worked through the system towards D7, but also with an eye to back-port to D5 and D6.

For here, other urls to test and extend for: tel:// (for phone numbers) and xmpp:// (for jabber IM)
These may be useful in a social networking scenario, among others. Also, moving towards the mobile browsers that are also phones, these could become more desired.

The XMPP URI stuff is something I had a very small part in a long time ago, but you can find more information here: http://wiki.jabber.org/index.php/XMPP_URIs and the RFC here: http://tools.ietf.org/html/rfc4622.

The tel URI is explained in http://www.ietf.org/rfc/rfc3966.txt and http://www.ietf.org/rfc/rfc2806.txt

Here are some examples of URL's to test against provided by http://msdn.microsoft.com/en-us/library/ms709071(VS.85).aspx and http://xmpp.org/extensions/xep-0147.html.

callto:192.168.103.77+type=ipcallto:someone@example.com+type=directory
callto:msils/someone@example.com+type=directory
callto:msils:1002/someone@example.com+type=directory
callto:12345+type=phone
callto:12345+gateway=fusion+type=phone
callto:someone@example.com
callto:12345+type=phone

xmpp:romeo@montague.net?message
xmpp:romeo@montague.net?message;subject=Test%20Message;body=Here%27s%20a%20test%20message

#11

mfer - January 13, 2009 - 12:05

I propose a 4 part proposal for moving forward with better validation. Instead of expanding valid_url to do everything we add some additional validation functions.

  • We expand valid_url for additional schemes. This would allow us to have urls that start with ical:// and others.
  • We expand valid_url for to allow international characters and international domains. Then we could have urls like http://例え.テスト/メインページ. These really aren't urls so much as they are irls. The url provided here works and is routable.
  • Provide a more generic IRI validation function that can handle the cases in #10.
  • Make field validation configurable. So, you can choose which validation function to use. (This may already be happening as part of the fields in core effort).

The proposed spec for IRIs is at http://tools.ietf.org/html/rfc3987. Thoughts?

#12

flickerfly - January 15, 2009 - 03:30

I like the sound of mfer's solution. Configurability means flexibility without compromise to security. So would we provide for custom validation of the URL, meaning the user puts in their own regex? I'm thinking something like the date/time config that allows custom time config.

My guts says "really bad idea", but might as well toss it on the table so that can get slaughtered logically instead of just by my gut reaction. :-)

#13

mfer - January 15, 2009 - 10:52

@flickerfly for url/uri validation I don't think we should allow the users to input their own regex. As part of the fields in core effort there are validators for fields. Developers can assign those. I want to see less configuration options. Maybe an option to set the allow schemes that has now web interface.

#14

hass - February 3, 2009 - 13:32

#15

hass - February 3, 2009 - 13:41

About extending the function like discussed here, I'd like to please you to make sure module developers are able to define what protocols are valid via params. For e.g. I'd like to reuse the function in my modules, but make sure only http/https is allowed. I need this because I' like to validate the URL prior to using it much later in drupal_http_request().

#16

alexanderpas - February 8, 2009 - 01:21

#17

alexanderpas - March 3, 2009 - 04:01

#18

dropcube - September 13, 2009 - 21:26

Subscribe

 
 

Drupal is a registered trademark of Dries Buytaert.