Actions
Bug #11149
closedURI.parse keeps '?' for query and '#' for fragment even if they are empty
    Bug #11149:
    URI.parse keeps '?' for query and '#' for fragment even if they are empty
  
Description
p = URI.parse('http://example.com/path?query#fragment')
p.query = ''
p.fragment = ''
puts p.to_s
will output "http://example.com/path?#" but I think it should be "http://example.com/path" without '?' and '#'
        
           Updated by naruse (Yui NARUSE) over 10 years ago
          Updated by naruse (Yui NARUSE) over 10 years ago
          
          
        
        
      
      - Status changed from Open to Assigned
- Assignee set to naruse (Yui NARUSE)
As URL Standard, current behavior is correct.
https://url.spec.whatwg.org/
But Google Chrome's behavior is like what you say.
I keep watching how W3C/WHATWG decide this behavior.
        
           Updated by davispuh (Dāvis Mosāns) over 10 years ago
          Updated by davispuh (Dāvis Mosāns) over 10 years ago
          
          
        
        
      
      Actually yes, I was wrong on this and it is expected behavior.
When one wants without '?' and '#' correct way is to set to nil and not to empty string ''
p.query = nil
p.fragment = nil
        
           Updated by nobu (Nobuyoshi Nakada) over 7 years ago
          Updated by nobu (Nobuyoshi Nakada) over 7 years ago
          
          
        
        
      
      At least, that test should not be in test_parse, but in test_set_component or others.
        
           Updated by naruse (Yui NARUSE) over 7 years ago
          Updated by naruse (Yui NARUSE) over 7 years ago
          
          
        
        
      
      - Status changed from Assigned to Rejected
Chrome also follows the behavior.
Actions