Hacktoberfest 2026: le issue che i maintainer hanno segnato per ottobre, aperte e adatte ai principianti. Sfoglia le issue Hacktoberfest

URI::MailTo::EMAIL_REGEXP matches whole strings but URI::RFC2396_PARSER.make_regexp matches partial strings

Aperta
#226 0 commenti 0 reazioni 0 assegnatari Vedi su GitHub

Nessuno ha ancora preso questa issue.

Valutazione

Difficoltà
4/5
Tempo stimato
3-5 giorni
Idoneità per principianti
45/100
Tipo di issue
Funzionalità
Chiarezza
Abbastanza chiara
Stato di attività
Tranquilla
Stack tecnologico
ruby
Ambito
api, backend

Direzione di ricerca

Esamina il punto di ingresso pubblico URI::RFC2396_PARSER.make_regexp e la sua interazione con URI::MailTo::EMAIL_REGEXP; determina innanzitutto la semantica di matching esistente e i test disponibili. Done dovrebbe preservare il comportamento predefinito attuale fornendo al contempo un’opzione esplicita di corrispondenza completa la cui copertura rifiuti gli spazi bianchi finali.

Scritto dal modello di indicizzazione a partire dal testo della issue.

Descrizione

The way to test if a string is a valid email address is to directly use URI::MailTo::EMAIL_REGEXP

require 'uri'

puts URI::MailTo::EMAIL_REGEXP.match?('me@example.com') # true
puts URI::MailTo::EMAIL_REGEXP.match?('me@example.com ') # false (trailing space)

However, the correct way to validate that a string is a valid URL is to wrap the regex in anchors:

require 'uri'
puts /\A#{URI::RFC2396_PARSER.make_regexp}\z/.match?('https://example.com/') # true
puts /\A#{URI::RFC2396_PARSER.make_regexp}\z/.match?('https://example.com/ ') # false (trailing space)

If I directly use make_regexp, that second string matches because of a partial match.

require 'uri'
puts URI::RFC2396_PARSER.make_regexp.match?('https://example.com/ ') # true (trailing space)

Same behavior if I pass schemes into make_regexp or use the too. I'm on Ruby 4.0.1 but I don't think this behavior changed recently.

Would it be okay if I made a PR adding a keyword argument to make_regexp? It would get called like:

URI::RFC2396_PARSER.make_regexp(full_match: true).match?('https://example.com/ ') # true (trailing space)

I figured changing the default behavior could be a breaking change for a lot of people and that doesn't feel worth it.

Lingua principale
Ruby
Stelle
125
Fork
65
Merge medio
6h 4m
PR unite (30g)
2

Guida per i contributori

Nessuna guida per i contributori indicizzata per questo repository

Come iniziare

  1. Leggi tutta la issue e poi la guida ai contributi del progetto.
  2. Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
  3. Fai un fork del repository e lavora su un branch.
  4. Apri una pull request che faccia riferimento al numero della issue.

Altre issue di ruby/uri

Tutte le issue di ruby/uri

Issue simili

Altre issue su Ruby

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.