1. 10 9月, 2020 1 次提交
    • J
      Fix XSS vulnerability in `translate` helper · 4ca2027d
      Jonathan Hefner 提交于
      Prior to this commit, when a translation key indicated that the
      translation text was HTML, the value returned by `I18n.translate` would
      always be marked as `html_safe`.  However, the value returned by
      `I18n.translate` could be an untrusted value directly from
      `options[:default]`.
      
      This commit ensures values directly from `options[:default]` are not
      marked as `html_safe`.
      4ca2027d
  2. 05 2月, 2020 2 次提交
  3. 18 12月, 2019 1 次提交
  4. 18 6月, 2019 1 次提交
  5. 09 3月, 2019 1 次提交
  6. 01 3月, 2019 1 次提交
    • X
      Removes unnecessary dot in regexp · 42ca13a9
      Xavier Noria 提交于
      A string S matches ([.]|\b)html if an only if matches \bhtml:
      
        * If S matches [.]html, then it matches \bhtml.
      
        * If S matches \bhtml, then it matches \bhtml.
      
      Reciprocally:
      
        * If S matches \bhtml, then it matches ([.]|\b)html.
      
      The character class can be removed, and since we are on it we remove the
      group too so that it is clear to a reader of the code that there is no
      grouping going on.
      
      References #35166.
      42ca13a9
  7. 05 2月, 2019 1 次提交
  8. 23 9月, 2018 1 次提交
    • Y
      Enable `Performance/UnfreezeString` cop · 1b86d901
      yuuji.yaginuma 提交于
      In Ruby 2.3 or later, `String#+@` is available and `+@` is faster than `dup`.
      
      ```ruby
      # frozen_string_literal: true
      
      require "bundler/inline"
      
      gemfile(true) do
        source "https://rubygems.org"
      
        gem "benchmark-ips"
      end
      
      Benchmark.ips do |x|
        x.report('+@') { +"" }
        x.report('dup') { "".dup }
        x.compare!
      end
      ```
      
      ```
      $ ruby -v benchmark.rb
      ruby 2.5.1p57 (2018-03-29 revision 63029) [x86_64-linux]
      Warming up --------------------------------------
                        +@   282.289k i/100ms
                       dup   187.638k i/100ms
      Calculating -------------------------------------
                        +@      6.775M (± 3.6%) i/s -     33.875M in   5.006253s
                       dup      3.320M (± 2.2%) i/s -     16.700M in   5.032125s
      
      Comparison:
                        +@:  6775299.3 i/s
                       dup:  3320400.7 i/s - 2.04x  slower
      
      ```
      1b86d901
  9. 03 7月, 2018 1 次提交
  10. 28 4月, 2018 1 次提交
  11. 23 3月, 2018 1 次提交
    • D
      Only create an array with default options if we have default options · 38526059
      Dillon Welch 提交于
      If the options passed in don't have a default key, there's no point in
      creating an array from those empty results when we can just go straight
      to creating an empty array.
      
      Benchmarks:
      ```ruby
      master_version with false
      {:FREE=>-2497, :T_STRING=>52, :T_ARRAY=>2000, :T_HASH=>1000, :T_IMEMO=>1}
      master_version with true
      {:FREE=>-3001, :T_ARRAY=>2000, :T_HASH=>1000}
      fast_version with false
      {:FREE=>-1001, :T_ARRAY=>1000}
      fast_version with true
      {:FREE=>-3001, :T_ARRAY=>2000, :T_HASH=>1000}
      Warming up --------------------------------------
      master_version with false
                             104.985k i/100ms
      master_version with true
                             118.737k i/100ms
      fast_version with false
                             206.013k i/100ms
      fast_version with true
                             107.005k i/100ms
      Calculating -------------------------------------
      master_version with false
                                1.970M (±24.6%) i/s -      8.924M in   5.010302s
      master_version with true
                                2.152M (±12.4%) i/s -     10.686M in   5.051588s
      fast_version with false
                                5.613M (±19.6%) i/s -     26.782M in   5.003740s
      fast_version with true
                                2.027M (±15.8%) i/s -      9.951M in   5.065670s
      
      Comparison:
      fast_version with false:  5613159.2 i/s
      master_version with true:  2152354.4 i/s - 2.61x  slower
      fast_version with true:  2027296.0 i/s - 2.77x  slower
      master_version with false:  1969824.9 i/s - 2.85x  slower
      ```
      
      Benchmark code:
      ```ruby
      begin
        require "bundler/inline"
      rescue LoadError => e
        $stderr.puts "Bundler version 1.10 or later is required. Please update
                      your Bundler"
        raise e
      end
      
      gemfile(true) do
        source "https://rubygems.org"
      
        gem "benchmark-ips"
        gem "rails"
      end
      
      def allocate_count
        GC.disable
        before = ObjectSpace.count_objects
        yield
        after = ObjectSpace.count_objects
        after.each { |k,v| after[k] = v - before[k] }
        after[:T_HASH] -= 1 # probe effect - we created the before hash.
        GC.enable
        result = after.reject { |k,v| v == 0 }
        GC.start
        result
      end
      
      def master_version(key)
        Array({}.delete(:default)).compact
      end
      
      def fast_version(key)
        if key
          Array({}.delete(:default)).compact
        else
          []
        end
      end
      
      def test
        puts "master_version with false"
        puts allocate_count { 1000.times { master_version(false) } }
        puts "master_version with true"
        puts allocate_count { 1000.times { master_version(true) } }
        puts "fast_version with false"
        puts allocate_count { 1000.times { fast_version(false) } }
        puts "fast_version with true"
        puts allocate_count { 1000.times { fast_version(true) } }
      
        Benchmark.ips do |x|
          x.report("master_version with false")  { master_version(false) }
          x.report("master_version with true") { master_version(true) }
          x.report("fast_version with false")    { fast_version(false) }
          x.report("fast_version with true")   { fast_version(true) }
          x.compare!
        end
      end
      
      test
      ```
      38526059
  12. 20 3月, 2018 1 次提交
    • D
      Memoize the result of gsubbing @virtual_path · 05eaa076
      Dillon Welch 提交于
      This gets called many times for each virtual_path, creating a new string
      each time that `translate` is called. We can memoize this so that it
      only happens once per virtual_path instead.
      05eaa076
  13. 21 10月, 2017 1 次提交
  14. 27 8月, 2017 1 次提交
  15. 24 7月, 2017 1 次提交
  16. 02 7月, 2017 1 次提交
  17. 01 7月, 2017 2 次提交
  18. 20 6月, 2017 1 次提交
  19. 03 6月, 2017 1 次提交
  20. 27 10月, 2016 1 次提交
    • X
      let Regexp#match? be globally available · 56832e79
      Xavier Noria 提交于
      Regexp#match? should be considered to be part of the Ruby core library. We are
      emulating it for < 2.4, but not having to require the extension is part of the
      illusion of the emulation.
      56832e79
  21. 07 8月, 2016 1 次提交
  22. 25 7月, 2016 1 次提交
  23. 19 12月, 2015 1 次提交
    • S
      debug_missing_translation configuration added to action_view · c1dbb13e
      Sameer Rahmani 提交于
      `I18n.translate` helper will wrap the missing translation keys
      in a <span> tag only if `debug_missing_translation` configuration has
      a truthy value. Default value is `true`. For example in `application.rb`:
      
          # in order to turn off missing key wrapping
          config.action_view.debug_missing_translation = false
      c1dbb13e
  24. 29 10月, 2015 1 次提交
  25. 19 9月, 2015 1 次提交
  26. 05 5月, 2015 2 次提交
  27. 24 4月, 2015 1 次提交
    • D
      Correct translate helper docs [ci skip] · 6ad5e7eb
      Derek Prior 提交于
      The documentation previously stated that calling `translate(".foo")` was
      equivalent to calling `I18n.translate("people.index.foo")` which is
      incorrect due to the various other functions of the `translate` view
      helper. This has been fixed.
      
      Additionally, a note about forcing the view helper to re-raise
      exceptions was added to the section detailing the handling of missing
      translations.
      
      Other cleanup includes:
      
      * Consistent formatting of code
      * Stop indenting bulleted list as a code sample
      * Tighten some of the language
      * Wrap at 80 characters.
      6ad5e7eb
  28. 05 4月, 2015 1 次提交
    • A
      Allow an array to be a default translation value. · 6f3c65f6
      Adam Prescott 提交于
      4.2.1 introduced a change to the way `translate`/`t` works with an
      option of `default: [[]]`. In 4.2.0, this would give a default value of
      `[]`, but in 4.2.1, it leads to a missing translation.
      
      `default: [[]]` is again allowed for cases where a default of `[]` is
      needed.
      
      This addresses GitHub issue 19640.
      6f3c65f6
  29. 21 3月, 2015 1 次提交
  30. 27 2月, 2015 1 次提交
    • U
      Fix regression when passing a value different of String. · 362557eb
      Ulisses Almeida 提交于
      The previous version of rails(4.2.0) you can pass objects
      to the default option of translation helper.
      
      For example:
      
      ```ruby
        t('foo', default: 1)
      ```
      
      But on rails 4.2.1 version this kind of use stopped to work,
      because started only to accept String types.
      
      Now with this fix we can use orther value types on this
      helper again.
      362557eb
  31. 03 1月, 2015 1 次提交
  32. 19 11月, 2014 1 次提交
  33. 06 9月, 2014 1 次提交
  34. 14 8月, 2014 1 次提交
  35. 13 5月, 2014 2 次提交
  36. 27 1月, 2014 1 次提交