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

Need path validation method #2

Open
renormalist opened this issue Feb 18, 2013 · 4 comments
Open

Need path validation method #2

renormalist opened this issue Feb 18, 2013 · 4 comments
Assignees

Comments

@renormalist
Copy link
Owner

It would be nice to have a validate() method to verify correctness
of incoming DPaths.

@ghost ghost assigned renormalist Feb 18, 2013
@davewood
Copy link
Contributor

Hi Steffen

I checked out your module yesterday and could not find a way to verify
if a string has a valid syntax path.

I expected

Data::DPath::Path->new( path => '!"§$%&/()=') to throw an error but no
matter what I send in as path iti s happily accepted.


Hmmm, they are normal paths, just looking a bit weird.

The only thing that's missing is that DPath does not find values when
tha path is not anchored with / at the beginning - I'm not sure what
semantics I planned or have.

Try attached test and see what I mean:

prove -vl strange-paths.t

Note how I split and nested the keys in $data according to the "/" in
your "garbage path".

It only fails with the un-anchored paths. Besides that it works.


Hi Steffen

thanks for the elaborate answer.

I have a web application where users can enter XPaths, Regular
Expressions, ... and hopefully soon to come .. DPaths

When I validate the users input all those modules provide the
possibility to "process" the input and in case of an invalid syntax an
error is thrown, which I re-present to the users as an error message.

In the case of Data::DPath no such validation "phase" seems available.
I thought perhaps that would be a sensible thing to add to make using
DPath more stable.

e.g.

Data::DPath::Path

. sub new {
. my $path_str = shift;
. if ($path_str =~ qr/^//xms) { die "Invalid DPath:Path syntax ..."; }
. }

@renormalist
Copy link
Owner Author

Thanks. Currently I try to allow "relative" paths by anchoring them to root
which would make your "garbage paths" valid.

Can you think of any other path examples which should actually be wrong?

Otherwise my validate() function currently looks like always returning true...

@renormalist
Copy link
Owner Author

Hi David,

I just rediscovered this issue. What's your current mindset on this?
Do you still need a validate() function?
I currently don't really know how to decide a path is valid as it can match crazy strings with paths that look similiarly crazy.

@davewood
Copy link
Contributor

davewood commented Jun 13, 2016

hey again,

I seem to have missed your question some time ago. :)

We could still use a validation method but I understand that it is not easy to implement. Even though paths might be very complex I suppose theyhave some kind of rule/grammar they follow.

ps: we are using Data::DPath extensively and are very happy so far.

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

No branches or pull requests

2 participants