なるようになるブログ

読書感想文かrailsについてかrubyについてか

rails commit log流し読み(2018/03/08)

2018/03/08分のコミットです。

CHANGELOGにのったコミットは以下の通りです。

activesupport/CHANGELOG.md


Merge pull request #32183 from kivikakk/uri-ext-fix

activesupport/lib/active_support/core_ext/uri.rbの修正です。

URI.unscapeunicode / escaped文字を混在した値を指定した場合に、エラーになってしまっていたのを修正しています。

# before
URI.unescape("\xe3\x83\x90")          # => "バ"
URI.unescape("%E3%83%90")             # => "バ"
URI.unescape("\xe3\x83\x90%E3%83%90") # => Encoding::CompatibilityError: incompatible character encodings: UTF-8 and ASCII-8BIT


# after
URI.unescape("\xe3\x83\x90")          # => "バ"
URI.unescape("%E3%83%90")             # => "バ"
URI.unescape("\xe3\x83\x90%E3%83%90") # => "ババ"

Merge pull request #32175 from bogdanvlviv/express-route_for-as-public-api

actionpack/lib/action_dispatch/routing/url_for.rbのdocの修正です。

ActionDispatch::Routing::UrlFor#route_forメソッドをpublic APIにしています。

元々特に意図があってprivateにしていた訳ではない、かつ、directメソッドと合わせて使うと便利そう、という事でpublic APIになりました。

例。

resources :buckets

direct :recordable do |recording|
  route_for(:bucket, recording.bucket)
end

direct :threadable do |threadable|
  route_for(:recordable, threadable.parent)
end

threadable_path(threadable) # => "/buckets/1"
threadable_url(threadable)  # => "http://example.com/buckets/1"

Add example of maintaining context with route_for

ActionDispatch::Routing::UrlFor#route_forメソッドのdocにhelperメソッドを使用した場合の説明を追加しています。


Quote string return values in doc examples [ci skip]

actionpack/lib/action_dispatch/routing/url_for.rbのdocの修正です。

先のdocの修正で追加した実行結果の例をダブルクォートで囲むよう修正しています。


Allow using inline style and script in the internal controllers

railties/lib/rails/application_controller.rbの修正です。

Rails内部で保持しているview(welcomeページや、mailer preview等)ではinline scriptを使えるよう、controllerでscript_src :unsafe_inline及びstyle_src :unsafe_inlineを指定するよう修正しています。

上記viewではinline style及びinline scriptを使用している為、アプリの設定に関わらずviewが正しく表示されるようにする為に上記指定を行うようにしています。


Add the ability to disable the global CSP in a controller

actionpack/lib/action_controller/metal/content_security_policy.rbの修正です。

controller単位でCSPを無効に出来るよう修正しています。

class LegacyPagesController < ApplicationController
  content_security_policy false, only: :index
end

無効にしたい場合、上記のように最初の引数にfalseを指定すればOKです。


Always yield a CSP policy instance

actionpack/lib/action_controller/metal/content_security_policy.rbの修正です。

CSPのインスタンスが生成されていない場合、強制的にインスタンスを生成するよう修正しています。

リクエストが実行される際にインスタンスが生成されているかどうかは、アプリのグローバル設定でCSPが有効かされているかどうかに依存しているのですが、それだとcontroller単位でCSPを変更したい場合に困る為、インスタンスが存在しない場合はリクエストを処理する際に生成するようにしています。