Skip to content

enhancement: encode urls before parsing #790

@JosiahParry

Description

@JosiahParry

When using httr2::url_parse() with a url that does not have spaces encoded we get an error from curl.

It would be a nice quality of life enhancement to use URLencode() prior to parsing the url.

The below is an example of the URL that one would get from ArcGIS Online this occurs when this item has spaces in the name—these are not URL encoded (I will be making an internal bug report!)—and using httr2::url_parse() with these urls fails.

url <- "https://services1.arcgis.com/hLJbHVT9ZrDIzK0I/arcgis/rest/services/California Cities Open Platform/FeatureServer/0"
httr2::url_parse(url)
#> Error in curl::curl_parse_url(url, baseurl = base_url, decode = FALSE): Failed to parse URL: Malformed input to a URL function
httr2::url_parse(URLencode(url))
#> <httr2_url>
#> https://services1.arcgis.com/hLJbHVT9ZrDIzK0I/arcgis/rest/services/California%20Cities%20Open%20Platform/FeatureServer/0
#> • scheme: https
#> • hostname: services1.arcgis.com
#> • path:
#> /hLJbHVT9ZrDIzK0I/arcgis/rest/services/California%20Cities%20Open%20Platform/FeatureServer/0

Created on 2025-07-24 with reprex v2.1.1

ref:

httr2/R/url.R

Line 27 in 924415c

curl <- curl::curl_parse_url(url, baseurl = base_url)

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions