Error 500 when editing a Wiki page that does not exist
<!--- Please read this! Before opening a new issue, make sure to search for keywords in the issues filtered by the "regression" or "bug" label: - https://gitlab.com/gitlab-org/gitlab/issues?label_name%5B%5D=regression - https://gitlab.com/gitlab-org/gitlab/issues?label_name%5B%5D=bug and verify the issue you're about to submit isn't a duplicate. ---> ### Summary In `WikisController#valid_encoding?`, we access `page.content.encoding`, but do not perform a `nil` check. This causes errors, such as: https://sentry.gitlab.net/gitlab/gitlabcom/issues/1460527 https://sentry.gitlab.net/gitlab/gitlabcom/issues/561605 ``` NoMethodError: undefined method `content' for nil:NilClass Did you mean? concern projects/wikis_controller.rb:153:in `block in valid_encoding?' @page.content.encoding == Encoding::UTF_8 gitlab/utils/strong_memoize.rb:26:in `strong_memoize' instance_variable_set(ivar(name), yield) projects/wikis_controller.rb:152:in `valid_encoding?' strong_memoize(:valid_encoding) do active_support/callbacks.rb:432:in `block in make_lambda' lambda { |target, _, &blk| target.send filter, &blk } active_support/callbacks.rb:417:in `block in invert_lambda' lambda { |*args, &blk| !l.call(*args, &blk) } ... (132 additional frame(s) were not displayed) NoMethodError: undefined method `content' for nil:NilClass Did you mean? concern ``` ### Steps to reproduce See https://sentry.gitlab.net/gitlab/gitlabcom/issues/1460527 - some edit operations are loading pages with `nil` content. ### Output of checks This bug happens on GitLab.com ### Possible fixes Guard `@page.content` access.
issue