ruby-core@ruby-lang.org archive (unofficial mirror)
 help / color / mirror / Atom feed
* [ruby-core:114983] [Ruby master Bug#19915] URI::HTTP.build accepts user: and password: keyboard arguments, but do not populate #user or #password
@ 2023-10-08 23:10 postmodern (Hal Brodigan) via ruby-core
  2023-10-09  0:25 ` [ruby-core:114984] [Ruby master Feature#19915] " jeremyevans0 (Jeremy Evans) via ruby-core
  2023-10-09 22:48 ` [ruby-core:114987] " postmodern (Hal Brodigan) via ruby-core
  0 siblings, 2 replies; 3+ messages in thread
From: postmodern (Hal Brodigan) via ruby-core @ 2023-10-08 23:10 UTC (permalink / raw
  To: ruby-core; +Cc: postmodern (Hal Brodigan)

Issue #19915 has been reported by postmodern (Hal Brodigan).

----------------------------------------
Bug #19915: URI::HTTP.build accepts user: and password: keyboard arguments, but do not populate #user or #password
https://bugs.ruby-lang.org/issues/19915

* Author: postmodern (Hal Brodigan)
* Status: Open
* Priority: Normal
* ruby -v: ruby 3.2.2 (2023-03-30 revision e51014f9c0) [x86_64-linux]
* Backport: 3.0: UNKNOWN, 3.1: UNKNOWN, 3.2: UNKNOWN
----------------------------------------
I noticed that `URI::HTTP.build` accepts the `user:` and `password:` keyword arguments, but does not actually set the `user` or `password` attributes of the built URI object. It does however correctly accept a `userinfo:` keyword argument.

## Steps To Reproduce

```ruby
uri = URI::HTTP.build(user: 'bob', password: 'secret', host: 'example.com', path: '/foo')
uri.user
uri.password
uri.to_s
```

### Expected Results

```ruby
uri.user
# => "bob"
uri.password
# => "secret"
uri.to_s
# => "http://bob:secret@example.com/foo"
```

### Actual Results

```ruby
uri.user
# => nil
uri.password
# => nil
uri.to_s
# => "http://example.com/foo"
```



-- 
https://bugs.ruby-lang.org/
 ______________________________________________
 ruby-core mailing list -- ruby-core@ml.ruby-lang.org
 To unsubscribe send an email to ruby-core-leave@ml.ruby-lang.org
 ruby-core info -- https://ml.ruby-lang.org/mailman3/postorius/lists/ruby-core.ml.ruby-lang.org/

^ permalink raw reply	[flat|nested] 3+ messages in thread

* [ruby-core:114984] [Ruby master Feature#19915] URI::HTTP.build accepts user: and password: keyboard arguments, but do not populate #user or #password
  2023-10-08 23:10 [ruby-core:114983] [Ruby master Bug#19915] URI::HTTP.build accepts user: and password: keyboard arguments, but do not populate #user or #password postmodern (Hal Brodigan) via ruby-core
@ 2023-10-09  0:25 ` jeremyevans0 (Jeremy Evans) via ruby-core
  2023-10-09 22:48 ` [ruby-core:114987] " postmodern (Hal Brodigan) via ruby-core
  1 sibling, 0 replies; 3+ messages in thread
From: jeremyevans0 (Jeremy Evans) via ruby-core @ 2023-10-09  0:25 UTC (permalink / raw
  To: ruby-core; +Cc: jeremyevans0 (Jeremy Evans)

Issue #19915 has been updated by jeremyevans0 (Jeremy Evans).

Tracker changed from Bug to Feature
ruby -v deleted (ruby 3.2.2 (2023-03-30 revision e51014f9c0) [x86_64-linux])
Backport deleted (3.0: UNKNOWN, 3.1: UNKNOWN, 3.2: UNKNOWN)

`URI::HTTP.build` does not accept keyword arguments, it accepts an array/hash. If you pass keyword arguments, they get turned into a hash, similarly to any Ruby method that does not explicitly accept keyword arguments.  The method only recognizes keys in `::URI::Generic::COMPONENT`.  The method documents what are the components it accepts:

```
Components are: scheme, userinfo, host, port, registry, path,
opaque, query, and fragment.
```

So this is not a bug.  If you would like to change it to accept `user` and `password`, that would be a feature request.

----------------------------------------
Feature #19915: URI::HTTP.build accepts user: and password: keyboard arguments, but do not populate #user or #password
https://bugs.ruby-lang.org/issues/19915#change-104855

* Author: postmodern (Hal Brodigan)
* Status: Open
* Priority: Normal
----------------------------------------
I noticed that `URI::HTTP.build` accepts the `user:` and `password:` keyword arguments, but does not actually set the `user` or `password` attributes of the built URI object. It does however correctly accept a `userinfo:` keyword argument.

## Steps To Reproduce

```ruby
uri = URI::HTTP.build(user: 'bob', password: 'secret', host: 'example.com', path: '/foo')
uri.user
uri.password
uri.to_s
```

### Expected Results

```ruby
uri.user
# => "bob"
uri.password
# => "secret"
uri.to_s
# => "http://bob:secret@example.com/foo"
```

### Actual Results

```ruby
uri.user
# => nil
uri.password
# => nil
uri.to_s
# => "http://example.com/foo"
```



-- 
https://bugs.ruby-lang.org/
 ______________________________________________
 ruby-core mailing list -- ruby-core@ml.ruby-lang.org
 To unsubscribe send an email to ruby-core-leave@ml.ruby-lang.org
 ruby-core info -- https://ml.ruby-lang.org/mailman3/postorius/lists/ruby-core.ml.ruby-lang.org/

^ permalink raw reply	[flat|nested] 3+ messages in thread

* [ruby-core:114987] [Ruby master Feature#19915] URI::HTTP.build accepts user: and password: keyboard arguments, but do not populate #user or #password
  2023-10-08 23:10 [ruby-core:114983] [Ruby master Bug#19915] URI::HTTP.build accepts user: and password: keyboard arguments, but do not populate #user or #password postmodern (Hal Brodigan) via ruby-core
  2023-10-09  0:25 ` [ruby-core:114984] [Ruby master Feature#19915] " jeremyevans0 (Jeremy Evans) via ruby-core
@ 2023-10-09 22:48 ` postmodern (Hal Brodigan) via ruby-core
  1 sibling, 0 replies; 3+ messages in thread
From: postmodern (Hal Brodigan) via ruby-core @ 2023-10-09 22:48 UTC (permalink / raw
  To: ruby-core; +Cc: postmodern (Hal Brodigan)

Issue #19915 has been updated by postmodern (Hal Brodigan).


I would expect either for unused options to raise an ArgumentError, or for `user:` and `password:` to be accepted and used. Since `URI::HTTP.build` is actually accepting a Hash [1], this makes it harder to validate the given Hash keys and raise an ArgumentError on unused keys.

[1]: https://github.com/ruby/uri/blob/f4999b61daa40f2c99fdc7159e2c85c036b22c67/lib/uri/http.rb#L59-L62

----------------------------------------
Feature #19915: URI::HTTP.build accepts user: and password: keyboard arguments, but do not populate #user or #password
https://bugs.ruby-lang.org/issues/19915#change-104857

* Author: postmodern (Hal Brodigan)
* Status: Open
* Priority: Normal
----------------------------------------
I noticed that `URI::HTTP.build` accepts the `user:` and `password:` keyword arguments, but does not actually set the `user` or `password` attributes of the built URI object. It does however correctly accept a `userinfo:` keyword argument.

## Steps To Reproduce

```ruby
uri = URI::HTTP.build(user: 'bob', password: 'secret', host: 'example.com', path: '/foo')
uri.user
uri.password
uri.to_s
```

### Expected Results

```ruby
uri.user
# => "bob"
uri.password
# => "secret"
uri.to_s
# => "http://bob:secret@example.com/foo"
```

### Actual Results

```ruby
uri.user
# => nil
uri.password
# => nil
uri.to_s
# => "http://example.com/foo"
```



-- 
https://bugs.ruby-lang.org/
 ______________________________________________
 ruby-core mailing list -- ruby-core@ml.ruby-lang.org
 To unsubscribe send an email to ruby-core-leave@ml.ruby-lang.org
 ruby-core info -- https://ml.ruby-lang.org/mailman3/postorius/lists/ruby-core.ml.ruby-lang.org/

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2023-10-09 22:49 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2023-10-08 23:10 [ruby-core:114983] [Ruby master Bug#19915] URI::HTTP.build accepts user: and password: keyboard arguments, but do not populate #user or #password postmodern (Hal Brodigan) via ruby-core
2023-10-09  0:25 ` [ruby-core:114984] [Ruby master Feature#19915] " jeremyevans0 (Jeremy Evans) via ruby-core
2023-10-09 22:48 ` [ruby-core:114987] " postmodern (Hal Brodigan) via ruby-core

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).