Skip to content
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

Symphony Warning: DOMXPath::evaluate(): Invalid expression #31

Closed
cylkee opened this issue Feb 13, 2017 · 12 comments
Closed

Symphony Warning: DOMXPath::evaluate(): Invalid expression #31

cylkee opened this issue Feb 13, 2017 · 12 comments

Comments

@cylkee
Copy link

cylkee commented Feb 13, 2017

An error occurred in /some-path/extensions/reflectionfield/fields/field.reflection.php around line 390

    385 // Find queries:
    386 preg_match_all('/\{[^\}]+\}/', $expression, $matches);
    387
    388 // Find replacements:
    389 foreach ($matches[0] as $match) {
    390 $result = $xpath->evaluate('string(//' . trim($match, '{}') . ')');
    391
    392 if (!is_null($result)) {
    393 $replacements[$match] = trim($result);
    394 } else { 

The reflection is complex using XPath functions: {entry/label} ({substring-before(entry/company/item, ' General Ltd.')}s)

The same reflection works in v1.4.2 on Symphony 2.6.11. If I change it to a simple reflection on this v2.0.0 instance, it works with {entry/label} ({entry/company/item})

Also, something weird is going on. I did a git submodule add git://github.com/symphonists/reflectionfield.git extensions/reflectionfield --recursive on a new installation of 2.6.11 and it gave me reflectionfield 2.0.0. See also version disorder on:

GitHub
reflectionfield1

and

symphonyextensions.com
reflectionfield2

@nitriques
Copy link
Member

The git command you set will fetch the latest version so 2.0.0 is the latest one. The bug is on the extension site. I've created the 2.0.0 release, thanks.

Also, 2.0.0 introduced changes. Did you check the read me ?

@cylkee
Copy link
Author

cylkee commented Mar 28, 2017

Thanks, @nitriques. I will try again at a later date when I have a Symphony installation I can test on.. I did check the readme, but it'd be good to have some example XPath expressions in there (one basic, one complex, one referencing a utility perhaps). I'd just like to check that it's intended behaviour that reflectionfield will interpret any XPath expression including those with functions? Because it seems like the version change breaks function usage, as per my original post.

@cylkee
Copy link
Author

cylkee commented Mar 28, 2017

Slightly unrelated, the readme is becoming mangled on symphonyextensions.com with headings overlapping paragraphs (visible in screenshot above). I would open an issue on symphony-extensions-network, but it seems only to be reflectionfield's readme.

Also the code block is rendering as one wrapping line (but maybe that is a site-wide issue).

@twiro
Copy link
Member

twiro commented Mar 28, 2017

Slightly unrelated, the readme is becoming mangled on symphonyextensions.com

Noticed that too and think a separate issue at the symphony-extension-network would be the best to discuss this as the problem isn't limited to rhe reflection field repo.

symphonyextensions.com is very restrictive regarding the formatting of the readme (it can't handle multiple H1s (like in this case), tables or code-blocks that use spaces instead of tabs). The question is if we can/will/should try to fix this on symphonyextensions.com or if we should set up more restrictive rules/recommendations regarding how to write/format the readme-files of extension-repos.

Having said this I think I'll best simply copy this paragraph and post a new issue in the SEN-repo... Any further discussion regarding this can be held over there!

@twiro
Copy link
Member

twiro commented Mar 28, 2017

Any further discussion regarding this can be held over there!

symphonists/symphony-extensions-network#16

@nitriques
Copy link
Member

@cylkee so the problem is the substring-before part ? It works without it ?

@nitriques nitriques added the bug label Mar 29, 2017
@cylkee
Copy link
Author

cylkee commented Mar 30, 2017

Yes.

{entry/label} ({substring-before(entry/company/item, ' General Ltd.')}s) works in v1.4.2 and at that time not in v2.0.0.

Removing the XPath function, forming simply {entry/label} ({entry/company/item}) made it work in v2.0.0

I've since gone back to v1.4.2.

Is it the case that it should accept any XPath, which includes functions? Or are there restrictions not disclosed in the Readme?

@nitriques
Copy link
Member

Maybe @nilshoerrmann knows why it would crash, since he made most of the code of version 2.0.0.

Does it works if the code is only {substring-before(entry/company/item, ' General Ltd.')} ?

@cylkee
Copy link
Author

cylkee commented Apr 11, 2017

Does it works if the code is only {substring-before(entry/company/item, ' General Ltd.')} ?

@nitriques No.

@cylkee
Copy link
Author

cylkee commented Apr 11, 2017

So, in an installation with Symphony 2.6.11 with reflectionfield 2.0.0 I have in fields/field.reflection.php line 390:

$result = $xpath->evaluate('string(//' . trim($match, '{}') . ')');

If I amend to:

$result = $xpath->evaluate('string(' . trim($match, '{}') . ')');

I must update the reflection from:

{entry/label} ({substring-before(entry/company/item, ' General Ltd.')}s)

to:

{//entry/label} ({substring-before(//entry/company/item, ' General Ltd.')}s)

for it to work. Or:

{data/reflection-field-handle/entry/label} ({substring-before(data/reflection-field-handle/entry/company/item, ' General Ltd.')}s)

Either of which is entirely proper, given the new XML data structure.

I don't know how to do a pull request though, I'm not Git-savvy.

@nitriques
Copy link
Member

@cylkee This might be a good start: https://help.github.com/articles/creating-a-pull-request/

If I amend to:

That was the fix I hope to land! I'll fix this right now. Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants