Movatterモバイル変換


[0]ホーム

URL:


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

Sign up
Appearance settings

[Yaml] Remove escaping regex#19782

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 ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Closed
GuilhemN wants to merge2 commits intosymfony:masterfromGuilhemN:ESCAPING
Closed

Conversation

@GuilhemN
Copy link
Contributor

@GuilhemNGuilhemN commentedAug 29, 2016
edited
Loading

QA
Branch?master
Bug fix?no
New feature?no
BC breaks?no
Deprecations?no
Tests pass?yes
Fixed tickets
LicenseMIT
Doc PR

This PR replaces regexs inEscaper by call tostrcspn. It is much easier to read imo and performance aren't degraded.
I also updated the data provider of a test because it was in practice testing nothing (it is checking if values are quoted as expected but as they always began with\t it was always quoted anyway).

Edit: quotes are moved to indicators as they are supported inside plain scalars as said by@stefk:

It seems those characters are perfectly valid in unquoted strings:

http://yaml.org/spec/1.2/spec.html#id2788859
http://yaml-online-parser.appspot.com/?yaml=foo%3A+ba%22r%0Abaz%3A+q%27u%27x%27%0A&type=canonical_yaml

publicstaticfunctionrequiresDoubleQuoting($value)
{
returnpreg_match('/'.self::REGEX_CHARACTER_TO_ESCAPE.'/u',$value);
returnstrlen($value) !==strcspn($value,implode('',self::$escapees));
Copy link
ContributorAuthor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

This would force escaping values containing",/ and\ that weren't escaped before. Does it matter ?

@GuilhemNGuilhemNforce-pushed theESCAPING branch 3 times, most recently fromb534d61 to87bc631CompareAugust 30, 2016 19:50
benchmark.php Outdated
@@ -0,0 +1,15 @@
<?php

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

not sure about this file :)

Copy link
ContributorAuthor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

Indeed, i should stop using-A ^^

'\\x18','\\x19','\\x1a','\\e','\\x1c','\\x1d','\\x1e','\\x1f',
'\\N','\\_','\\L','\\P');
privatestatic$escapees =array(
'\\','\\\\','\\"','"','/',
Copy link
ContributorAuthor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

BTW this fixes a "bug",/ was missing.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

Shouldn't this be done in 2.7 then?

Copy link
ContributorAuthor

@GuilhemNGuilhemNSep 2, 2016
edited
Loading

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

It works in 2.7, it should be escaped but that's not mandatory.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

so why doing it then?

Copy link
ContributorAuthor

@GuilhemNGuilhemNDec 7, 2016
edited
Loading

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

Actually that's not clear what we should do here.Non-printable characters must be escaped but/ is aprintable character (the spec says\/ is available for json compatibily), so I guess it's up to us to decide what to do.

For readability/ should indeed be better while\/ is more compliant with json. If you prefer/ I'll revert this change.

@fabpot
Copy link
Member

As it's not a bug fix, this should be done in master.

@GuilhemNGuilhemN changed the base branch from2.7 tomasterAugust 31, 2016 18:07
@GuilhemNGuilhemNforce-pushed theESCAPING branch 2 times, most recently fromd317288 tob377df8CompareAugust 31, 2016 18:14
@GuilhemN
Copy link
ContributorAuthor

ok, retargeted and rebased.
So no refactoring won't be merged in older branches? That's probably a good thing :)

@fabpot
Copy link
Member

That's the main idea, refactorings do not fix anything, so they should be done in master (the only exception is when it gives a huge performance improvement and the changes are trivial).

GuilhemN reacted with thumbs up emoji

privatestaticfunctionisBinaryString($value)
{
return !preg_match('//u',$value) ||preg_match('/[^\x09-\x0d\x20-\xff]/',$value);
return !preg_match('//u',$value) ||preg_match('/[^\x00-\x1f\x20-\xff]/',$value);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

What's the reason for this change?

Copy link
ContributorAuthor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

Because these caracters are escapable in double quoted strings

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

Ah okay, maybe we should add a comment with some reference to an external source or something like that to help understanding the code.

Copy link
ContributorAuthor

@GuilhemNGuilhemNSep 27, 2016
edited
Loading

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

in fact i'm not even sure we should use!!binary when dumping, all characters are supported in double-quoted scalars anyway.
I'll try to find what the spec says about that.

@nicolas-grekas
Copy link
Member

nicolas-grekas commentedDec 6, 2016
edited
Loading

Well, since you changed some char ranges, this looks like a bug fix to me. About the const, removing it is a BC break.
Thus, I think I'd prefer keeping the regexp and focus on the other changes for 2.7.

@stof
Copy link
Member

stof commentedDec 6, 2016

About the const, removing it is a BC break.

@nicolas-grekas the whole class is marked as internal, so not covered by the BC promise

returnpreg_match('/[ \s\' " \: \{ \} \[ \] , & \* \# \?] | \A[ \- ? | < > = ! % @ ` ]/x',$value);
// First character is an indicator
// @see http://yaml.org/spec/1.2/spec.html#c-indicator
if ($value &&1 ===strspn($value[0],'-?&*!|<>\'"=%@`')) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

this is broken for the empty string (btw, the simpler fix for that is probably to add the empty string in the array of values above)

Copy link
ContributorAuthor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

Indeed, good catch!

'slash' =>array('/','/'),
'backslash' =>array('\\','\\'),
'next-line' =>array("\xC2\x85",'"\\N"'),
'non-breaking-space' =>array('',''),
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

shouldn't this be"\_" in YAML ?

GuilhemN reacted with thumbs up emoji
Copy link
ContributorAuthor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

Sure, the test is wrong.

@nicolas-grekas
Copy link
Member

So, to help moving this one forward, I'm personnaly 👎 on this:

This PR replaces regexs in Escaper by call to strcspn. It is much easier to read imo and performance aren't degraded.

This is subjective, with no clear technical benefit, and will create merge conflicts that are thus not worth it.

@GuilhemN
Copy link
ContributorAuthor

GuilhemN commentedDec 27, 2016
edited
Loading

@nicolas-grekas this PR mostly intents to improve readability and maintainability (do you think it's obvious whatpreg_match('/[ \s \' " \: \{ \} \[ \] , & \* \# \?] | \A[ \- ? | < > = ! % @ ]/x', $value); does ?).
About merge conflicts I understand your concern but this file isnot modified often (last modification of a line updated here was in january 2015) so I don't think it would be a problem.

It also improves a bit scalars dumping when quotes are in the middle of the scalar (e.g.foo'bar was dumped as'foo''bar' now it is dumped asfoo'bar as it is a valid plain scalar).

Anyway, we should at least updatethe tests which are currently useless.

@fabpot
Copy link
Member

Closing as I agree with@nicolas-grekas here.@GuilhemN Can you submit a PR for the tests though?

@fabpotfabpot closed thisMar 5, 2017
@GuilhemNGuilhemN deleted the ESCAPING branchMarch 6, 2017 20:30
@GuilhemNGuilhemN mentioned this pull requestMar 6, 2017
fabpot added a commit that referenced this pull requestMar 6, 2017
This PR was merged into the 2.7 branch.Discussion----------[Yaml] Fix the tests| Q             | A| ------------- | ---| Branch?       | 2.7| Bug fix?      | no| New feature?  | no| BC breaks?    | no| Deprecations? | no| Tests pass?   | yes| Fixed tickets || License       | MIT| Doc PR        |Fix tests that are currently useless (previously part of#19782).Commits-------5107b94 [Yaml] Fix the tests
Sign up for freeto join this conversation on GitHub. Already have an account?Sign in to comment

Reviewers

@nicolas-grekasnicolas-grekasnicolas-grekas left review comments

@stofstofstof left review comments

@xabbuhxabbuhxabbuh left review comments

Assignees

No one assigned

Projects

None yet

Milestone

No milestone

Development

Successfully merging this pull request may close these issues.

6 participants

@GuilhemN@fabpot@nicolas-grekas@stof@xabbuh@carsonbot

[8]ページ先頭

©2009-2025 Movatter.jp