php / php/php-src

FILTER_VALIDATE_URL returns false when underscore present in URL

Aperta
#17,842 5 commenti 0 reazioni 0 assegnatari Vedi su GitHub

Nessuno ha ancora preso questa issue.

Bug Extension: filter Status: Verified
Lingua principale
C
Stelle
40.4k
Fork
8.1k
Merge medio
2g 13h
PR unite (30g)
96

Descrizione

Description

The following code:

<?php
var_dump(filter_var('https://sub_domain.example.com', FILTER_VALIDATE_URL));
var_dump(filter_var('https://ex_ample.com', FILTER_VALIDATE_URL));

Resulted in this output:

bool(false)
bool(false)

But I expected this output instead:

string(30) "https://sub_domain.example.com"
string(20) "https://ex_ample.com"

The underscore is a valid character according to the RFC 2396 section 2.3:

Unreserved Characters

Data characters that are allowed in a URI but do not have a reserved
purpose are called unreserved. These include upper and lower case
letters, decimal digits, and a limited set of punctuation marks and
symbols.

  unreserved  = alphanum | mark

  mark        = "-" | "_" | "." | "!" | "~" | "*" | "'" | "(" | ")"

Unreserved characters can be escaped without changing the semantics
of the URI, but this should not be done unless the URI is being used
in a context that does not allow the unescaped character to appear.

But this filter fails if a underscore is present in the domain or subdomain portion of the URL.

This RFC is superseded by RFC 3986, but the underscore is still in the unreserved characters:

unreserved = ALPHA / DIGIT / "-" / "." / "_" / "~"

PHP Version

PHP 8.4.4

Operating System

No response

Guida per i contributori

Apri la guida per i contributori

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.

Direzione di ricerca

Inizia riproducendo le chiamate a filter_var() con FILTER_VALIDATE_URL mostrate nell’issue, quindi traccia l’implementazione della validazione degli URL in php-src. Confronta la gestione degli underscore nei componenti host e sottodominio con le sezioni RFC citate. Il lavoro è completato quando gli esempi documentati producono i risultati di validazione attesi e i test pertinenti coprono questo comportamento.

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

Valutazione

Stack tecnologico
c, php
Ambito
backend
Tipo di issue
Bug
Difficoltà
3/5
Tempo stimato
1-2 giorni
Stato di attività
Ferma
Chiarezza
Abbastanza chiara
Idoneità per principianti
42/100

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.