Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

URL-encode URLs #348

Open
wants to merge 2 commits into
base: 4.x
Choose a base branch
from

Conversation

BlackbitDevs
Copy link

@BlackbitDevs BlackbitDevs commented Aug 20, 2024

Currently there is only one Utils::encode() method which gets used to encode URLs as well as textual content.
For example in

$xml = '<url><loc>' . Utils::encode($this->getLoc()) . '</loc>';

the <loc> gets encoded with
return htmlspecialchars($string, ENT_QUOTES | ENT_SUBSTITUTE, 'UTF-8');

With the following code

$url = new \Presta\SitemapBundle\Sitemap\Url\UrlConcrete('http://example.org/umlaut_url_ä');
var_dump($url->toXml());

the generated XML is:

<url>
  <loc>http://example.org/umlaut_url_ä</loc>
</url>

Actually this is not a valid URL according to RFC3986 (also see https://stackoverflow.com/questions/1856785/characters-allowed-in-a-url for summary). Although such URLs work when being called in a browser because the browser URL-encodes it, this library should follow the RFC imho.

With this PR above code would generate this XML:

<url>
  <loc>http://example.org/umlaut_url_%C3%A4</loc>
</url>

This is exactly the same as when you call http://example.org/umlaut_url_ä in your browser and then copy-paste the URL to a text editor.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant