Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit c10baf9

Browse filesBrowse files
committed
feature #24372 [DowCrawler] Default to UTF-8 when possible (nicolas-grekas)
This PR was merged into the 3.4 branch. Discussion ---------- [DowCrawler] Default to UTF-8 when possible | Q | A | ------------- | --- | Branch? | 3.4 | Bug fix? | no | New feature? | yes | BC breaks? | no | Deprecations? | no | Tests pass? | yes | Fixed tickets | #17258 | License | MIT | Doc PR | - This can't be ambiguous, let's use UTF-8 when possible. Commits ------- 73eda66 [DowCrawler] Default to UTF-8 when possible
2 parents 260d2f0 + 73eda66 commit c10baf9
Copy full SHA for c10baf9

File tree

1 file changed

+3
-3
lines changed
Filter options

1 file changed

+3
-3
lines changed

‎src/Symfony/Component/DomCrawler/Crawler.php

Copy file name to clipboardExpand all lines: src/Symfony/Component/DomCrawler/Crawler.php
+3-3Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -127,8 +127,8 @@ public function add($node)
127127
/**
128128
* Adds HTML/XML content.
129129
*
130-
* If the charset is not set via the content type, it is assumed
131-
* to be ISO-8859-1, which is the default charset defined by the
130+
* If the charset is not set via the content type, it is assumed to be UTF-8,
131+
* or ISO-8859-1 as a fallback, which is the default charset defined by the
132132
* HTTP 1.1 specification.
133133
*
134134
* @param string $content A string to parse as HTML/XML
@@ -161,7 +161,7 @@ public function addContent($content, $type = null)
161161
}
162162

163163
if (null === $charset) {
164-
$charset = 'ISO-8859-1';
164+
$charset = preg_match('//u', $content) ? 'UTF-8' : 'ISO-8859-1';
165165
}
166166

167167
if ('x' === $xmlMatches[1]) {

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.