PDA

View Full Version : [OPEN] [FIXED-244][3.x, 2.x] Ext.form.VTypes.url allows for text before https? or ftp



jay@moduscreate.com
15 Sep 2009, 5:21 AM
current code regex:


File: src/widgets/form/VTypes.js


url = /(((https?)|(ftp)):\/\/([\-\w]+\.)+\w{2,3}(\/[%\-\w]+(\.\w{2,})?)*(([\w\-\.\?\\\/+@&#;`~=%!]*)(\.\w{2,})?)*\/?)/i;



Fix:


url = /(((^https?)|(^ftp)):\/\/([\-\w]+\.)+\w{2,3}(\/[%\-\w]+(\.\w{2,})?)*(([\w\-\.\?\\\/+@&#;`~=%!]*)(\.\w{2,})?)*\/?)/i;


Initial problem:

http://www.extjs.com/forum/showthread.php?t=80337


HI all,

we are using text filed vtype:'url' its working fine
but in one case it allows wrong url.
for ex:hfgsdfhttps://www.domain.com its accepts as url(its not giving error )but before https we have enter wrong data.

plz any body can help to resolve this.


Thanks & regards
jsuser

evant
15 Sep 2009, 6:44 AM
Fix applied to svn in rev #5351 for patch release 3.0.3.

mystix
15 Sep 2009, 8:23 AM
that regex there needs to be cleaned up a little bit more (the first 4 capturing groups can be collapsed into a single non-capturing group).
there's also an excessive (mis)use of capturing groups when capturing isn't even required.

suggested regex:


url = /^(?:https?|ftp):\/\/(?:[\-\w]+\.)+\w{2,3}(?:\/[%\-\w]+(?:\.\w{2,})?)*(?:(?:[\w\-\.\?\\\/+@&#;`~=%!]*)(?:\.\w{2,})?)*\/?/i;


might also want to consider adding matches for other protocols like gopher / telnet etc as detailed in this blog post:
http://www.geekzilla.co.uk/view2D3B0109-C1B2-4B4E-BFFD-E8088CBC85FD.htm
(i don't quite fully agree with some portions of the regex proposed in the blog post though)

p.s. the other VType regexes should also be inspected for other unnecessary capturing groups.

jay@moduscreate.com
15 Sep 2009, 8:31 AM
Yes, that would optimize it quite a bit.

disizben
23 Sep 2009, 11:44 PM
Hi all,

There is another problem with url vtype.

The url
http://localhost/ is not valid !