Skip to content

Commit 3a90d78

Browse files
committed
Ruby: Fix Rails view file regex
This picks up non-nested template files correctly.
1 parent 48890b4 commit 3a90d78

File tree

2 files changed

+20
-1
lines changed

2 files changed

+20
-1
lines changed

ruby/ql/lib/codeql/ruby/frameworks/ActionController.qll

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -374,7 +374,8 @@ predicate controllerTemplateFile(ActionControllerClass cls, ErbFile templateFile
374374
controllerPath = getActionControllerClassRelativePath(cls) and
375375
// `sourcePrefix` is either a prefix path ending in a slash, or empty if
376376
// the rails app is at the source root
377-
sourcePrefix = [controllerPath.regexpCapture("^(.*/)app/controllers/(?:.*?)/(?:[^/]*)$", 1), ""] and
377+
sourcePrefix =
378+
[controllerPath.regexpCapture("^(.*/)app/controllers/(?:[^/]+/)?(?:[^/]*)$", 1), ""] and
378379
controllerPath = sourcePrefix + "app/controllers/" + subPath + "_controller.rb"
379380
|
380381
sourcePrefix + "app/views/" + subPath = templateFile.getParentContainer().getRelativePath()

ruby/ql/test/library-tests/frameworks/action_controller/ActionController.expected

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -348,7 +348,25 @@ httpResponses
348348
| app/controllers/foo/bars_controller.rb:44:5:44:17 | call to render | app/controllers/foo/bars_controller.rb:44:12:44:17 | "show" |
349349
actionControllerHelperMethods
350350
getAssociatedControllerClasses
351+
| app/controllers/comments_controller.rb:1:1:104:3 | CommentsController | app/views/comments/create.html.erb:0:0:0:0 | app/views/comments/create.html.erb |
352+
| app/controllers/comments_controller.rb:1:1:104:3 | CommentsController | app/views/comments/destroy.html.erb:0:0:0:0 | app/views/comments/destroy.html.erb |
353+
| app/controllers/comments_controller.rb:1:1:104:3 | CommentsController | app/views/comments/index.html.erb:0:0:0:0 | app/views/comments/index.html.erb |
354+
| app/controllers/comments_controller.rb:1:1:104:3 | CommentsController | app/views/comments/show.html.erb:0:0:0:0 | app/views/comments/show.html.erb |
355+
| app/controllers/photos_controller.rb:1:1:10:3 | PhotosController | app/views/photos/foo.html.erb:0:0:0:0 | app/views/photos/foo.html.erb |
356+
| app/controllers/photos_controller.rb:1:1:10:3 | PhotosController | app/views/photos/show.html.erb:0:0:0:0 | app/views/photos/show.html.erb |
357+
| app/controllers/posts_controller.rb:1:1:32:3 | PostsController | app/views/posts/index.html.erb:0:0:0:0 | app/views/posts/index.html.erb |
358+
| app/controllers/posts_controller.rb:1:1:32:3 | PostsController | app/views/posts/show.html.erb:0:0:0:0 | app/views/posts/show.html.erb |
359+
| app/controllers/posts_controller.rb:1:1:32:3 | PostsController | app/views/posts/upvote.html.erb:0:0:0:0 | app/views/posts/upvote.html.erb |
351360
controllerTemplateFiles
361+
| app/controllers/comments_controller.rb:1:1:104:3 | CommentsController | app/views/comments/create.html.erb:0:0:0:0 | app/views/comments/create.html.erb |
362+
| app/controllers/comments_controller.rb:1:1:104:3 | CommentsController | app/views/comments/destroy.html.erb:0:0:0:0 | app/views/comments/destroy.html.erb |
363+
| app/controllers/comments_controller.rb:1:1:104:3 | CommentsController | app/views/comments/index.html.erb:0:0:0:0 | app/views/comments/index.html.erb |
364+
| app/controllers/comments_controller.rb:1:1:104:3 | CommentsController | app/views/comments/show.html.erb:0:0:0:0 | app/views/comments/show.html.erb |
365+
| app/controllers/photos_controller.rb:1:1:10:3 | PhotosController | app/views/photos/foo.html.erb:0:0:0:0 | app/views/photos/foo.html.erb |
366+
| app/controllers/photos_controller.rb:1:1:10:3 | PhotosController | app/views/photos/show.html.erb:0:0:0:0 | app/views/photos/show.html.erb |
367+
| app/controllers/posts_controller.rb:1:1:32:3 | PostsController | app/views/posts/index.html.erb:0:0:0:0 | app/views/posts/index.html.erb |
368+
| app/controllers/posts_controller.rb:1:1:32:3 | PostsController | app/views/posts/show.html.erb:0:0:0:0 | app/views/posts/show.html.erb |
369+
| app/controllers/posts_controller.rb:1:1:32:3 | PostsController | app/views/posts/upvote.html.erb:0:0:0:0 | app/views/posts/upvote.html.erb |
352370
headerWriteAccesses
353371
| app/controllers/comments_controller.rb:30:5:30:35 | call to []= | content-type | app/controllers/comments_controller.rb:30:39:30:49 | ... = ... |
354372
| app/controllers/comments_controller.rb:31:5:31:46 | call to set_header | content-length | app/controllers/comments_controller.rb:31:43:31:45 | 100 |

0 commit comments

Comments
 (0)