url_absolute fails with spaces in url

Abierto
#401 0 comentarios 1 reacción 0 asignados Ver en GitHub

Nadie ha tomado este issue todavía.

Evaluación

Dificultad
2/5
Tiempo estimado
1-3 horas
Aptitud para principiantes
48/100
Tipo de issue
Error
Claridad
Bastante claro
Estado de actividad
Estancado
Stack tecnológico
r
Área
backend

Línea de trabajo

Start by reproducing the reported url_absolute() examples with spaces and with utils::URLencode(), then inspect the url_absolute() entry point and its handling of invalid URLs. Clarify whether the expected result is encoding the spaces or warning instead of returning NA, and add regression coverage showing that URLs with spaces no longer fail silently.

Escrito por el modelo de indexación a partir del texto del issue.

Descripción

bug url :crown:

xml_attr(x, "href") returns un-encoded URLs if that's how they appear in the source, but then those URLs fail in url_absolute.

url <- "/filename with spaces.pdf" 
xml2::url_absolute(
  url,
  base = "https://example.com/"
)
#> [1] NA
xml2::url_absolute(
  utils::URLencode(url),
  base = "https://example.com/"
)
#> [1] "https://example.com/filename%20with%20spaces.pdf"

Created on 2023-08-23 with reprex v2.0.2

url_absolute() gets confused if the URL contains spaces, and silently returns NA. This should at least warn the user, but it might be preferable to deal with it directly.

This is where I found it in the wild:

base_url <- "https://www.copyright.gov/fair-use/fair-index.html"

pdf_urls <-
  rvest::read_html(base_url) |> 
  rvest::html_element("table") |> 
  rvest::html_elements("tr>td:first-of-type>a:first-of-type") |>
  rvest::html_attr("href")

pdf_urls[[10]] |> 
  rvest::url_absolute(base_url)
#> [1] NA

pdf_urls[[10]] |> 
  utils::URLencode() |> 
  rvest::url_absolute(base_url)
#> [1] "https://www.copyright.gov/fair-use/summaries/ONeil%20v.%20Ratajkowski%20No.%2019%20CIV.%209769%20(S.D.N.Y.%202021).pdf"

Created on 2023-08-23 with reprex v2.0.2

Lenguaje dominante
R
Estrellas
227
Forks
86
Métricas de merge de PR
Sin PR fusionados en 30 d

Preparar el entorno

Primeros pasos

  1. Lee el issue completo y luego la guía de contribución del proyecto.
  2. Comenta en el issue que vas a ocuparte — evita que dos personas hagan lo mismo.
  3. Haz un fork del repositorio y trabaja en una rama.
  4. Abre un pull request que haga referencia al número del issue.

Más de r-lib/xml2

Todos los issues de r-lib/xml2

Issues similares

Más issues de R

Recibe los nuevos issues en tu correo

Un resumen breve de issues de GitHub para principiantes.