-
-
Notifications
You must be signed in to change notification settings - Fork 9.6k
DOMCrawler: removing extra break lines and spaces? #21302
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
Comments
This was proposed, and rejected, a few years ago in #11470. Two methods were proposed: I still think it'd be a good idea. Let's ping @symfony/deciders to see if they've changed their opinion about this. Thanks! |
Adding these Personally I'm extending the Crawler class, I couldn't anymore clutter my code all over with this: $ref = preg_replace('/\s+/', ' ', trim($node
->filter('div.numero_ref')
->text())); Now I just have to do: $ref = $node
->filter('div.numero_ref')
->cleanText(); |
It's very common to trim strings in tests, so 👍 for me but this should be opt-in with a new method or a defaulted argument in |
Can we move forward on this ? |
…t() method (Simperfit) This PR was merged into the 4.4 branch. Discussion ---------- [DomCrawler] add a normalizeWhitespace argument to text() method | Q | A | ------------- | --- | Branch? | 4.4 | Bug fix? | no | New feature? | yes <!-- please update src/**/CHANGELOG.md files --> | BC breaks? | no <!-- see https://symfony.com/bc --> | Deprecations? | no <!-- please update UPGRADE-*.md and src/**/CHANGELOG.md files --> | Tests pass? | yes <!-- please add some, will be required by reviewers --> | Fixed tickets | #21302, #23626 <!-- #-prefixed issue number(s), if any --> | License | MIT | Doc PR | todo <!-- required for new features --> <!-- Replace this notice by a short README for your feature/bugfix. This will help people understand your PR and can be used as a start for the documentation. Additionally (see https://symfony.com/roadmap): - Bug fixes must be submitted against the lowest maintained branch where they apply (lowest branches are regularly merged to upper ones so they get the fixes too). - Features and deprecations must be submitted against branch 4.4. - Legacy code removals go to the master branch. --> I've taken #24412, rebased with 4.4, fixed the comments in the PR. cc @xabbuh @stof @nicolas-grekas Commits ------- 1746718 [DomCrawler] add a value() method, normalize whitespaces
We are currently implementing a functional test, testing content of the following code:
We need to test content of the
.availability
element. Hence, we use something like:However, as there are some line breaks, this test fails as following:
We are used to fix this output using a code like:
Yet, it may be a good idea to add a new
$cleanedOutput = false
parameter to thetext()
method?The text was updated successfully, but these errors were encountered: