Bug 54594 - Expose isValidProtocol() in KURL.h.
Summary: Expose isValidProtocol() in KURL.h.
Status: RESOLVED FIXED
Alias: None
Product: WebKit
Classification: Unclassified
Component: Platform (show other bugs)
Version: 528+ (Nightly build)
Hardware: Other OS X 10.5
: P2 Normal
Assignee: Nobody
URL:
Keywords:
Depends on:
Blocks: 54438
  Show dependency treegraph
 
Reported: 2011-02-16 15:26 PST by James Kozianski
Modified: 2011-03-08 09:41 PST (History)
6 users (show)

See Also:


Attachments
Patch (3.00 KB, patch)
2011-02-16 15:27 PST, James Kozianski
no flags Details | Formatted Diff | Diff
Patch (3.11 KB, patch)
2011-02-16 15:44 PST, James Kozianski
no flags Details | Formatted Diff | Diff
Patch (3.23 KB, patch)
2011-03-06 20:39 PST, James Kozianski
no flags Details | Formatted Diff | Diff
Patch (2.86 KB, patch)
2011-03-07 15:46 PST, James Kozianski
koz: review-
Details | Formatted Diff | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description James Kozianski 2011-02-16 15:26:41 PST
Expose isValidProtocol() in KURL.h.
Comment 1 James Kozianski 2011-02-16 15:27:22 PST
Created attachment 82710 [details]
Patch
Comment 2 James Kozianski 2011-02-16 15:32:15 PST
The implementation of isValidProtocol() in KURLGoogle.cpp is basically a copy/paste of the one in KURL.cpp - I'm not sure if this is kosher from a code duplication or plagiarism point of view (the function is quite trivial and any reasonable implementation would be isomorphic to the original) so any guidance on this matter would be appreciated.
Comment 3 Adam Barth 2011-02-16 15:37:52 PST
Comment on attachment 82710 [details]
Patch

View in context: https://bugs.webkit.org/attachment.cgi?id=82710&action=review

> Source/WebCore/ChangeLog:7
> +        Expose isValidProtocol() in KURL.h.
> +        https://bugs.webkit.org/show_bug.cgi?id=54594
> +

Why?
Comment 4 James Kozianski 2011-02-16 15:42:09 PST
(In reply to comment #3)
> (From update of attachment 82710 [details])
> View in context: https://bugs.webkit.org/attachment.cgi?id=82710&action=review
> 
> > Source/WebCore/ChangeLog:7
> > +        Expose isValidProtocol() in KURL.h.
> > +        https://bugs.webkit.org/show_bug.cgi?id=54594
> > +
> 
> Why?

For general use, but in particular because I want to check for invalid schemes being used in calls to navigator.registerProtocolHandler (see bug 54438).

Sorry, I'll add that to the ChangeLog.
Comment 5 James Kozianski 2011-02-16 15:44:44 PST
Created attachment 82714 [details]
Patch
Comment 6 Adam Barth 2011-02-16 23:28:49 PST
CCing URL folks
Comment 7 Alexey Proskuryakov 2011-02-16 23:46:10 PST
Should we rename this to isValidProtocolName() when exposing? Or even isValidSchemeName()?
Comment 8 Eric Seidel (no email) 2011-02-17 01:49:03 PST
Comment on attachment 82714 [details]
Patch

This seems tricky.  How flexible should this be?  Should this allow leading/trailing spaces?  Why is this only implemented for the Google side?  is "a" a valid scheme?  Seems this says it is.  Can we test this?
Comment 9 James Kozianski 2011-02-17 13:14:06 PST
(In reply to comment #8)
> (From update of attachment 82714 [details])
> This seems tricky.  How flexible should this be?  Should this allow leading/trailing spaces?  Why is this only implemented for the Google side?  is "a" a valid scheme?  Seems this says it is.  Can we test this?

There is already an implementation in KURL.cpp of which this is just a copy (see my above comment). And I think the most intuitive behaviour for this function would be to validate exactly what the spec says at http://tools.ietf.org/html/rfc3986#section-3.1.

As for testing, this function isn't exposed to the browser directly (it is used internally by KURL.cpp), but in my other patch (bug 54438) which causes navigator.registerProtocolHandler() to use this function to verify protocols passed to it, I add test cases that exercise this function directly.
Comment 10 James Kozianski 2011-02-17 13:24:34 PST
(In reply to comment #7)
> Should we rename this to isValidProtocolName() when exposing? Or even isValidSchemeName()?

I think its current name is the most consistent - the current public interface for KURL uses 'protocol' by itself (protocolIs(), setProtocol(), etc). Also, it could be argued that in the context of a URL it is implied that we are referring to the name of a protocol.
Comment 11 Alexey Proskuryakov 2011-02-17 13:36:28 PST
> I think its current name is the most consistent - the current public interface for KURL uses 'protocol' by itself (protocolIs(), setProtocol(), etc). 

OK.

> Also, it could be argued that in the context of a URL it is implied that we are referring to the name of a protocol.

This I don't agree with. KURL knows a lot about semantics of URLs (even default ports!), so it's not always about names.
Comment 12 James Kozianski 2011-02-17 16:59:32 PST
(In reply to comment #11)
> > Also, it could be argued that in the context of a URL it is implied that we are referring to the name of a protocol.
> 
> This I don't agree with. KURL knows a lot about semantics of URLs (even default ports!), so it's not always about names.

True, that's a good point.
Comment 13 Ojan Vafai 2011-02-21 21:35:23 PST
Comment on attachment 82714 [details]
Patch

View in context: https://bugs.webkit.org/attachment.cgi?id=82714&action=review

> Source/WebCore/platform/KURLGoogle.cpp:136
> +bool isValidProtocol(const String& protocol)

This is missing a comment from the KURL.cpp version. May as well make the copy-paste exact. Also, can you put a comment explaining that this is copy-pasted from there?
Comment 14 James Kozianski 2011-03-06 20:35:04 PST
(In reply to comment #13)
> (From update of attachment 82714 [details])
> View in context: https://bugs.webkit.org/attachment.cgi?id=82714&action=review
> 
> > Source/WebCore/platform/KURLGoogle.cpp:136
> > +bool isValidProtocol(const String& protocol)
> 
> This is missing a comment from the KURL.cpp version. May as well make the copy-paste exact. Also, can you put a comment explaining that this is copy-pasted from there?

Done.
Comment 15 James Kozianski 2011-03-06 20:39:41 PST
Created attachment 84917 [details]
Patch
Comment 16 Adam Barth 2011-03-06 20:51:48 PST
dave_levin have been working to remove duplicated code in KURL.cpp and KURLGoogle.cpp.  I noticed this comment:

+ // NOTE This is a copy of the function in KURL.cpp.

Maybe we can move this function outside the ifdef so we don't have to copy/paste it?
Comment 17 David Levin 2011-03-06 22:24:24 PST
(In reply to comment #16)
> dave_levin have been working to remove duplicated code in KURL.cpp and KURLGoogle.cpp.  I noticed this comment:
> 
> + // NOTE This is a copy of the function in KURL.cpp.
> 
> Maybe we can move this function outside the ifdef so we don't have to copy/paste it?

Yes, please do (see the bottom of KURL.cpp). (It seems silly to duplicate code between these two files for things that are identical so I got rid of some. Let's not add more.)
Comment 18 David Levin 2011-03-06 22:24:48 PST
Comment on attachment 84917 [details]
Patch

Per above comment.
Comment 19 James Kozianski 2011-03-07 15:45:22 PST
(In reply to comment #17)
> (In reply to comment #16)
> > dave_levin have been working to remove duplicated code in KURL.cpp and KURLGoogle.cpp.  I noticed this comment:
> > 
> > + // NOTE This is a copy of the function in KURL.cpp.
> > 
> > Maybe we can move this function outside the ifdef so we don't have to copy/paste it?
> 
> Yes, please do (see the bottom of KURL.cpp). (It seems silly to duplicate code between these two files for things that are identical so I got rid of some. Let's not add more.)

Right, of course. Done.
Comment 20 James Kozianski 2011-03-07 15:46:40 PST
Created attachment 84991 [details]
Patch
Comment 21 James Kozianski 2011-03-07 15:52:23 PST
Comment on attachment 84991 [details]
Patch

Compile errors.
Comment 22 James Kozianski 2011-03-07 15:59:54 PST
(In reply to comment #21)
> (From update of attachment 84991 [details])
> Compile errors.

Hm. This is made a bit more complicated by the fact that the duplicated versions are identical in code, but because they are in different files they get linked with different static inline methods (see isSchemeChar() and isSchemeFirstChar() in KURL.cpp and KURLGoogle.cpp).

What would be the best way to move forward here?
Comment 23 David Levin 2011-03-07 16:19:28 PST
(In reply to comment #22)
> (In reply to comment #21)
> > (From update of attachment 84991 [details] [details])
> > Compile errors.
> 
> Hm. This is made a bit more complicated by the fact that the duplicated versions are identical in code, but because they are in different files they get linked with different static inline methods (see isSchemeChar() and isSchemeFirstChar() in KURL.cpp and KURLGoogle.cpp).
> 
> What would be the best way to move forward here?

If needed, you can do separate (duplicate) methods.
Comment 24 James Kozianski 2011-03-07 16:38:47 PST
> If needed, you can do separate (duplicate) methods.

Okay, I've revived the old patch as per our chat.
Comment 25 David Levin 2011-03-07 17:32:56 PST
Comment on attachment 84917 [details]
Patch

So sad but it seems we need to do this.  If you get a better idea, feel free to submit another patch.

Something to consider is moving those inline functions to KURL.h Anyway r+ on this.
Comment 26 WebKit Commit Bot 2011-03-08 09:41:30 PST
Comment on attachment 84917 [details]
Patch

Clearing flags on attachment: 84917

Committed r80566: <http://trac.webkit.org/changeset/80566>
Comment 27 WebKit Commit Bot 2011-03-08 09:41:37 PST
All reviewed patches have been landed.  Closing bug.