-
-
Notifications
You must be signed in to change notification settings - Fork 9.6k
[DomCrawler] add a value() method, normalize whitespaces #24412
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
Conversation
xabbuh
commented
Oct 3, 2017
•
edited by javiereguiluz
Loading
edited by javiereguiluz
Q | A |
---|---|
Branch? | 4.1 |
Bug fix? | no |
New feature? | yes |
BC breaks? | no |
Deprecations? | no |
Tests pass? | yes |
Fixed tickets | #21302, #23626 |
License | MIT |
Doc PR | TODO |
{ | ||
$this->assertEquals("one two\nthree ", $this->createTestCrawler()->filterXPath('//div[@id="text-whitespaces"]')->value(), '->value() returns the node value of the first element of the node list'); | ||
|
||
$this->createTestCrawler()->filterXPath('//ol')->value(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this should be a separate test like testValueThrowsExceptionWhenNodeListEmpty
. if the above call aleady fails with InvalidArgumentException, the test would still pass.
So, on 3.4 people will have to update their codebase to Couldn't we drop the 3.4 step and just make the 4.0 change? I don't really see the benefits of the 3.4 step, apart from adding work. |
There is no need to update the code in 4.0 again. You could omit the argument then, but it's not necessary. |
UPGRADE-3.4.md
Outdated
---------- | ||
|
||
* added an argument to the `text()` method to opt-in normalizing whitespaces, not passing `true` is deprecated, for the | ||
previous behavior of the `text()` method, use the new `value()` method |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
* Added an argument to the `text()` method to opt-in normalizing whitespaces, not passing `true` is deprecated. For the
previous behavior of the `text()` method, use the new `value()` method.
? (see dots)
UPGRADE-4.0.md
Outdated
DomCrawler | ||
---------- | ||
|
||
* the `text()` method now normalizes whitespaces of the node text value |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
same. Compared to above/below blocks this should be sentences no?
I'm sorry I don't get the migration path at all. If we must add a flag because there is no other migration path, let's settle on having a flag and keep it. This would mean zero deprecation (but for ppl extending the class, but that's edgy.) |
Oh, and we could then, in 4.1, deprecate the flag and replace it by this value() method. |
public function text($normalizeWhitespaces = false) | ||
{ | ||
if (!$normalizeWhitespaces) { | ||
@trigger_error(sprintf('Not normalizing whitespace characters when using the %s() method is deprecated since version 3.4. The %s() method will return the first node\'s value with whitespaces being normalized in Symfony 4.0. Use the value() method instead if you do not want to have whitespaces normalized.', __METHOD__, __METHOD__), E_USER_DEPRECATED); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This deprecation is not required and should be removed.
Also, the added arg is a bc break right now, should be done using func_get_arg()
Fair enough, I reverted the deprecation. Status: Needs Review |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That's still strange, sorry :)
What about deprecating test()
, and add a $normalizeWhitespace = true
flag to value()
The flag is a requirement to me, I can't find any better path that would be migration-path-friendly.
But by defaulting to "true", value could just be good by default, WDYT?
I understand what you mean, but if we did that, |
I the context of an HTML crawler, I think that The normalization you are doing here for |
I suggest to postpone this PR for Symfony 4.1 to not rush anything into core with which we may not be completely satisfied. |
@xabbuh Time to resurrect this PR? |
@xabbuh Still interested in finishing this PR? |
To avoid all that upgrade path mess with the method parameters, I'd suggest just adding a new method as I proposed initially. |
@xabbuh do you want me to finish this one ? |
@Simperfit If you have some time, please feel free to take over. 👍 |
@Simperfit Is this PR still on your radar? |
@fabpot doing it today
Le lun. 8 juil. 2019 à 12:07, Fabien Potencier <notifications@github.com> a
écrit :
… @Simperfit <https://github.com/Simperfit> Is this PR still on your radar?
—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
<#24412?email_source=notifications&email_token=AA2KV4QR2NX6V3BY3S3QHXLP6MGVPA5CNFSM4D5RWEZKYY3PNVWWK3TUL52HS4DFVREXG43VMVBW63LNMVXHJKTDN5WW2ZLOORPWSZGODZMTYZA#issuecomment-509164644>,
or mute the thread
<https://github.com/notifications/unsubscribe-auth/AA2KV4QZWOSVZ5VKUC5ALUTP6MGVPANCNFSM4D5RWEZA>
.
|
closing in favour of #32440 |
Thank you for taking over @Simperfit! |
…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