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

Bug: Lexical parser prohibits querying on fieldnames containing a questionmark #1

Closed
elofu17 opened this issue May 19, 2016 · 3 comments

Comments

@elofu17
Copy link

elofu17 commented May 19, 2016

For some reason, the puppetdb people thought it was a good idea to have a questionmark in one of the Events fieldnames: "latest_report?"

From the Events manual (https://docs.puppet.com/puppetdb/4.0/api/query/v4/events.html):
latest_report? (Boolean): whether the event occurred in the most recent Puppet run (per-node).

The github project Puppet Explorer (https://github.com/spotify/puppetexplorer/) use 'node-puppetdbquery'.

If I do a query for "#event.latest_report?=true", Puppet Explorer show me a red banner complaining about:

Lexical error on line 1. Unrecognized text. 
#event.latest_report?=true
--------------------^

If I try removing the questionmark, I get a red banner stating that I should use a fieldname with the questionmark:

'latest_report' is not a queryable object for events, known queryable objects are ["certname","configuration_version","containing_class","containment_path", "environment","file","latest_report?","line","message","new_value","old_value","property","report",
"report_receive_time","resource_title","resource_type","run_end_time","run_start_time","status",
"timestamp"]

See the "latest_report?" there in the middle.

Can you please make the lexical parser not bail on the questionmark character?
The error is generated here:

return this.parseError('Lexical error on line ' + (this.yylineno + 1) + '. Unrecognized text.\n' + this.showPosition(), {

@elofu17
Copy link
Author

elofu17 commented Jun 21, 2016

A colleague of mine solved it for me:

In line 713 (

rules: [/^(?:\s+)/,/^(?:\()/,/^(?:\))/,/^(?:\[)/,/^(?:\])/,/^(?:\{)/,/^(?:\})/,/^(?:=)/,/^(?:!=)/,/^(?:~)/,/^(?:!~)/,/^(?:<=)/,/^(?:>=)/,/^(?:>)/,/^(?:<)/,/^(?:\*)/,/^(?:#)/,/^(?:not\b)/,/^(?:and\b)/,/^(?:or\b)/,/^(?:true\b)/,/^(?:false\b)/,/^(?:-?\d+)/,/^(?:"(\\.|[^\\"])*")/,/^(?:'(\\.|[^\\'])*')/,/^(?:\.)/,/^(?:[-\w_:]+)/,/^(?:@@)/,/^(?:@)/,/^(?:$)/],
), add a "?" to the 4th expression at the end, "/^(?:[-\w_:]+)/," --> "/^(?:[-\w_?:]+)/,"

Like this:
rules: [/^(?:\s+)/,/^(?:()/,/^(?:))/,/^(?:[)/,/^(?:])/,/^(?:{)/,/^(?:})/,/^(?:=)/,/^(?:!=)/,/^(?:)/,/^(?:!)/,/^(?:<=)/,/^(?:>=)/,/^(?:>)/,/^(?:<)/,/^(?:*)/,/^(?:#)/,/^(?:not\b)/,/^(?:and\b)/,/^(?:or\b)/,/^(?:true\b)/,/^(?:false\b)/,/^(?:-?\d+)/,/^(?:"(.|[^\"])")/,/^(?:'(.|[^\'])')/,/^(?:.)/,/^(?:[-\w_:]+)/,/^(?:@@)/,/^(?:@)/,/^(?:$)/],

Is changed to:
rules: [/^(?:\s+)/,/^(?:()/,/^(?:))/,/^(?:[)/,/^(?:])/,/^(?:{)/,/^(?:})/,/^(?:=)/,/^(?:!=)/,/^(?:)/,/^(?:!)/,/^(?:<=)/,/^(?:>=)/,/^(?:>)/,/^(?:<)/,/^(?:*)/,/^(?:#)/,/^(?:not\b)/,/^(?:and\b)/,/^(?:or\b)/,/^(?:true\b)/,/^(?:false\b)/,/^(?:-?\d+)/,/^(?:"(.|[^\"])")/,/^(?:'(.|[^\'])')/,/^(?:.)/,/^(?:[-\w_?:]+)/,/^(?:@@)/,/^(?:@)/,/^(?:$)/],

Now I can execute queries that use the "latest_report?" fieldname, like this:
#report { latest_report?=true and noop=true and status="unchanged" }

Unless this change allow too much or makes something insecure, please update your code accordingly.

@dalen
Copy link
Owner

dalen commented Jun 29, 2016

it is possible to just quote the property in the query, like #event."latest_report?"=true. But it is a bit silly to have to do that, so I'll fix it.

@dalen dalen closed this as completed in 8b18303 Jun 29, 2016
@elofu17
Copy link
Author

elofu17 commented Jun 29, 2016

:-)
Thanks!

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