Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8552321
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T14:23:58+00:00 2026-06-11T14:23:58+00:00

I recently had a problem when comparing two NSURLs and compare one NSURL with

  • 0

I recently had a problem when comparing two NSURLs and compare one NSURL with an NSString(which is a URL address), the situation is I got an NSURLRequest from somewhere, I may or may not know the URL address it points to, and I have an URL NSString, say “http://m.google.com”, now I need to check if the URL in that NSURLRequest is the same as the URL string I had:

[[request.URL.absoluteString lowercaseString] isEqualToString: [self.myAddress lowercaseString]];

this returns NO as the absoluteString gives me “http://m.google.com/” whereas my string is “http://m.google.com” without a slash in the end, even if I create the NSURLRequest using

[NSURLRequest requestWithURL:[NSURL URLWithString:@"http://m.google.com"]]

it still gives me “http://m.google.com/” for absoluteString, I wonder is there any reliable way to compare to NSURL or one NSURL and one NSString?

  1. check if one ‘contains’ another, but this is not reliable as ‘http://m.google.com/blabla’ contains ‘http://m.google.com’.

  2. convert the NSString to NSURL and use the isEqual method to compare two NSURL and hopefully NSURL’s implementation of isEqual can figure it out?

  3. based on step 2, but convert each NSURL to a standard URL using standardizedURL?

Thanks a lot!

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-11T14:23:59+00:00Added an answer on June 11, 2026 at 2:23 pm

    If you care only about the trailing slash ambiguity, you can dispense with this question quickly by knowing that NSURL path trims the trailing slash.

    But I like the idea of a category method on NSURL that implements some standards-based equivalence (“equivalence” is probably a better term than equality in this case).

    @RobNapier refers to a related question with a good answer that points to RFC2616. Another relevant standard for url syntax is RFC1808.

    The tough part is deciding what we mean by equivalence, for example, what about differing queries or fragments (anchor links)? The code below errs on the side of permissiveness for most of these ambiguities…

    // in NSURL+uriEquivalence.m
    
    - (BOOL)isEquivalent:(NSURL *)aURL {
    
        if ([self isEqual:aURL]) return YES;
        if ([[self scheme] caseInsensitiveCompare:[aURL scheme]] != NSOrderedSame) return NO;
        if ([[self host] caseInsensitiveCompare:[aURL host]] != NSOrderedSame) return NO;
    
        // NSURL path is smart about trimming trailing slashes
        // note case-sensitivty here
        if ([[self path] compare:[aURL path]] != NSOrderedSame) return NO;
    
        // at this point, we've established that the urls are equivalent according to the rfc
        // insofar as scheme, host, and paths match
    
        // according to rfc2616, port's can weakly match if one is missing and the
        // other is default for the scheme, but for now, let's insist on an explicit match
        if ([self port] || [aURL port]) {
            if (![[self port] isEqual:[aURL port]]) return NO;
            if (![[self query] isEqual:[aURL query]]) return NO;
        }
    
        // for things like user/pw, fragment, etc., seems sensible to be
        // permissive about these.
        return YES;
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I recently found a situation in which I had two related variables that had
I recently had a problem with two threads sticking in deadlock because they weren't
Recently I had a problem in a costumer's computer. Our installer would hang during
I've recently had a horrible problem with QTCreator. After the first time of running
Here's a problem I've had recently that just HAS to be a common pain
I recently had this problem on a test: given a set of points m
I recently had a little problem using a jquery plugin with coffeescript (within the
Recently we had an encoding problem in our system : If we had the
I recently had the following problem: I'm developing a numerical library in Python (called
I recently had to troubleshoot a performance problem with a slow grid load. Upon

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.