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

View #exists?/#list_jobs broken with regex control characters #232

Open
hsitter opened this issue Apr 25, 2017 · 0 comments
Open

View #exists?/#list_jobs broken with regex control characters #232

hsitter opened this issue Apr 25, 2017 · 0 comments
Labels

Comments

@hsitter
Copy link

hsitter commented Apr 25, 2017

If a view contains regular expression control characters, such as () view.exists?('snap (build)') and transitively view.list_jobs(('snap (build)') will not work.

e.g. here's a list

I, [2017-04-25T11:31:06.175580 #27075]  INFO -- : Obtaining views based on filter ''
D, [2017-04-25T11:31:06.175721 #27075] DEBUG -- : GET /api/json?tree=views[name]
D, [2017-04-25T11:31:06.262497 #27075] DEBUG -- : HTTP Code: 200, Response Body: {"_class":"hudson.model.Hudson","views":[{"_class":"hudson.model.ListView","name":"0 release ☉"},{"_class":"hudson.model.ListView","name":"1 stable ⚛ git stable"},{"_class":"hudson.model.ListView","name":"2 unstable ☣ git master"},{"_class":"hudson.plugins.status_view.StatusView","name":"3 red ⚕"},{"_class":"hudson.model.ListView","name":"4 release LTS ◎"},{"_class":"hudson.plugins.view.dashboard.Dashboard","name":"dash"},{"_class":"hudson.model.ListView","name":"iso"},{"_class":"hudson.model.ListView","name":"mergers"},{"_class":"hudson.model.ListView","name":"mgmt"},{"_class":"hudson.model.ListView","name":"plasma"},{"_class":"hudson.model.ListView","name":"qt"},{"_class":"hudson.plugins.view.dashboard.Dashboard","name":"snap (build)"},{"_class":"hudson.plugins.status_view.StatusView","name":"stable_plasma (red)"},{"_class":"hudson.plugins.status_view.StatusView","name":"testy"},{"_class":"hudson.model.ListView","name":"watcher"}]}

It does contain {"_class":"hudson.plugins.view.dashboard.Dashboard","name":"snap (build)"}. Yet calling view.list_jobs('snap (build)') will result in an exception being raised RuntimeError: The view snap (build) doesn't exists on the server.

Reason being #list_jobs internally does the following

  raise "The view #{view_name} doesn't exists on the server"\
    unless exists?(view_name)

#exists? in turn calls

  list(view_name).include?(view_name)

and in #list the view_name is then interpolated into a regex

      view_names << view["name"] if view["name"] =~ /#{filter}/i

at this point the "filter" (which was our view_name) will produce a bogus regex as we'll effectively have /snap (build)/i which isn't at all what the initial method call of #list_jobs wanted.

To fix this exists?(x) should probably be

    def exists?(view_name)
      list.include?(view_name)
    end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants