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

Allow node names to be passed to getNodeName #95

Merged
merged 1 commit into from
Dec 29, 2013

Conversation

dantleech
Copy link
Member

This was required in my shell where the path arguments are sometimes relative node names,

@dbu
Copy link
Member

dbu commented Dec 7, 2013

Hm, the phpdoc ja quite clear that you must pass valid absolute paths to this method. Can you Post a Link where you call this? If its user input, you might rather absolutize and normalize first. Imagine i type .. to get up one level.

@dantleech
Copy link
Member Author

Infact its used in phpcr-utils: https://github.com/phpcr/phpcr-utils/blob/master/src/PHPCR/Util/Console/Command/NodeTouchCommand.php#L108

If the spec says the path should be absolute I should fix that in my code -- but maybe we should throw an exception if there are no path delimiters in the given "path", otherwise

$nodeName = PathHelper::nodeName('foobar');
echo $nodeName;

yields oobar which isn't right.

@dbu
Copy link
Member

dbu commented Dec 8, 2013

okay, oobar is certainly not good :-) we could validate that the path is absolute and throw an exception otherwise. we could call self::assertValidAbsolutePath with the default parameters so that it throws an exception.

regardless of this, the touch command should validate that the path is absolute and throw an error if its not absolute. there is no context available there, and i think there is little value in creating nodes unter the root node if you do not specify the leading slash.

@dbu
Copy link
Member

dbu commented Dec 20, 2013

what should we do here? validate the parameter to getNodeName? i am a bit concerned about the overhead we generate for this. maybe we should just insist that this must be an absolute path, or do a simpler check for a leading slash?

and add validation in the touch command parameter?

@dbu
Copy link
Member

dbu commented Dec 25, 2013

@dantleech would you agree with my proposal to add validation in the touch command and just specify that the client code must be sure to pass in a valid absolute path to getNodeName? constantly validating any parameters could get rather expensive.

@dantleech
Copy link
Member Author

Not sure, I think if we allow this behavior it is going to make people scratch their heads in the future. But looking at the code again, we could do this without any "overhead":

$strpos = strpos($path, '/');
if (false === $strpos) { throw Exception(); }
return substr($path, $strpos + 1);

@dbu
Copy link
Member

dbu commented Dec 26, 2013

okay, that makes sense. lets use self::error(sprintf('Path '%s' is not an absolute path', $path));

can you update the PR?

@dbu
Copy link
Member

dbu commented Dec 28, 2013

if you can update this way, we can merge and tag 1.1.0-RC1 hopefully.

@dantleech
Copy link
Member Author

Updated.

dbu added a commit that referenced this pull request Dec 29, 2013
Allow node names to be passed to getNodeName
@dbu dbu merged commit 988c131 into phpcr:master Dec 29, 2013
@dbu
Copy link
Member

dbu commented Dec 29, 2013

great, thanks!

@dantleech
Copy link
Member Author

hmm, this causes problems in jackalope-doctrine-dbal:

1) Jackalope\Observation\EventFilterIdentifiersTest::testFilter

PHPCR\RepositoryException: Path "" must be an absolute path

/home/travis/build/jackalope/jackalope-doctrine-dbal/vendor/phpcr/phpcr-utils/src/PHPCR/Util/PathHelper.php:269

/home/travis/build/jackalope/jackalope-doctrine-dbal/vendor/phpcr/phpcr-utils/src/PHPCR/Util/PathHelper.php:237

/home/travis/build/jackalope/jackalope-doctrine-dbal/vendor/jackalope/jackalope/src/Jackalope/Item.php:180

/home/travis/build/jackalope/jackalope-doctrine-dbal/vendor/jackalope/jackalope/src/Jackalope/Node.php:1410

/home/travis/build/jackalope/jackalope-doctrine-dbal/vendor/jackalope/jackalope/src/Jackalope/Item.php:155

/home/travis/build/jackalope/jackalope-doctrine-dbal/vendor/jackalope/jackalope/src/Jackalope/Node.php:107

/home/travis/build/jackalope/jackalope-doctrine-dbal/vendor/jackalope/jackalope/tests/Jackalope/TestCase.php:116

/home/travis/build/jackalope/jackalope-doctrine-dbal/vendor/jackalope/jackalope/tests/Jackalope/Observation/EventFilterIdentifiersTest.php:79

/home/travis/build/jackalope/jackalope-doctrine-dbal/vendor/jackalope/jackalope/tests/Jackalope/Observation/EventFilterIdentifiersTest.php:62

/home/travis/build/jackalope/jackalope-doctrine-dbal/vendor/jackalope/jackalope/tests/Jackalope/Observation/EventFilterIdentifiersTest.php:12

@dbu
Copy link
Member

dbu commented Jan 4, 2014

this was because of very bad mocking code in TestCase, see jackalope/jackalope#199

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

Successfully merging this pull request may close these issues.

2 participants