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

[Routing] make xml loader more tolerant #7268

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

Merged
merged 2 commits into from
Mar 6, 2013
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
[Routing] make xml loader more tolerant
schemes and methods may also be delimited by whitespace, comma or pipe.
this eases migration as now schemes="GET|POST" also works
  • Loading branch information
Tobion committed Mar 5, 2013
commit 41ad9d8eb22b0908b72167c2eaa44d3a4d10f0f5
8 changes: 4 additions & 4 deletions 8 src/Symfony/Component/Routing/Loader/XmlFileLoader.php
Original file line number Diff line number Diff line change
Expand Up @@ -126,8 +126,8 @@ protected function parseRoute(RouteCollection $collection, \DOMElement $node, $p
$node->removeAttribute('pattern');
}

$schemes = array_filter(explode(' ', $node->getAttribute('schemes')));
$methods = array_filter(explode(' ', $node->getAttribute('methods')));
$schemes = preg_split('/[\s,\|]++/', $node->getAttribute('schemes'), -1, PREG_SPLIT_NO_EMPTY);
$methods = preg_split('/[\s,\|]++/', $node->getAttribute('methods'), -1, PREG_SPLIT_NO_EMPTY);
Copy link
Member

Choose a reason for hiding this comment

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

why 2 + ?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It prevents backtracking. So its a performance thing (which I also implemented for UrlMatching/route compiling some time ago).

Copy link
Contributor

Choose a reason for hiding this comment

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

I would say it's a micro-optim which:

  • makes the code unclear,
  • is really useless as you want to use the compiled version where perf matters.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Well its standard syntax for regular expressions. Just less known.

Copy link
Contributor

Choose a reason for hiding this comment

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

btw where could there be any backtracking here ?

Copy link
Contributor

Choose a reason for hiding this comment

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

(but thanks for the tip++ anyway!)


list($defaults, $requirements, $options) = $this->parseConfigs($node, $path);

Expand All @@ -154,8 +154,8 @@ protected function parseImport(RouteCollection $collection, \DOMElement $node, $
$type = $node->getAttribute('type');
$prefix = $node->getAttribute('prefix');
$host = $node->hasAttribute('host') ? $node->getAttribute('host') : null;
$schemes = $node->hasAttribute('schemes') ? array_filter(explode(' ', $node->getAttribute('schemes'))) : null;
$methods = $node->hasAttribute('methods') ? array_filter(explode(' ', $node->getAttribute('methods'))) : null;
$schemes = $node->hasAttribute('schemes') ? preg_split('/[\s,\|]++/', $node->getAttribute('schemes'), -1, PREG_SPLIT_NO_EMPTY) : null;
$methods = $node->hasAttribute('methods') ? preg_split('/[\s,\|]++/', $node->getAttribute('methods'), -1, PREG_SPLIT_NO_EMPTY) : null;

list($defaults, $requirements, $options) = $this->parseConfigs($node, $path);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,16 +17,6 @@

<xsd:element name="routes" type="routes" />

<xsd:simpleType name="word">
<xsd:restriction base="xsd:string">
<xsd:pattern value="([a-zA-Z]){3,}"/>
</xsd:restriction>
</xsd:simpleType>

<xsd:simpleType name="stringlist">
<xsd:list itemType="word"/>
</xsd:simpleType>

<xsd:complexType name="routes">
<xsd:choice minOccurs="0" maxOccurs="unbounded">
<xsd:element name="import" type="import" />
Expand All @@ -49,8 +39,8 @@
<xsd:attribute name="path" type="xsd:string" />
<xsd:attribute name="pattern" type="xsd:string" />
<xsd:attribute name="host" type="xsd:string" />
<xsd:attribute name="schemes" type="stringlist" />
<xsd:attribute name="methods" type="stringlist" />
<xsd:attribute name="schemes" type="xsd:string" />
<xsd:attribute name="methods" type="xsd:string" />
</xsd:complexType>

<xsd:complexType name="import">
Expand All @@ -60,8 +50,8 @@
<xsd:attribute name="type" type="xsd:string" />
<xsd:attribute name="prefix" type="xsd:string" />
<xsd:attribute name="host" type="xsd:string" />
<xsd:attribute name="schemes" type="stringlist" />
<xsd:attribute name="methods" type="stringlist" />
<xsd:attribute name="schemes" type="xsd:string" />
<xsd:attribute name="methods" type="xsd:string" />
</xsd:complexType>

<xsd:complexType name="element">
Expand Down
Morty Proxy This is a proxified and sanitized view of the page, visit original site.