copy_tuner_client 0.4.11 → 0.4.12

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 8f419a6b60b709e50adf9471b24b9cfa9ea9c11b
4
- data.tar.gz: 3f20340aabb91929c0c62c0ebefe3669539470b9
3
+ metadata.gz: 065504cc3f7dfc961ad953d04a27337c74e54adb
4
+ data.tar.gz: bb3a4c5e3d9b3915b7564aea2a086a353069d2de
5
5
  SHA512:
6
- metadata.gz: 25f0c0c8ebbf1961c4e4a94f83aca5cd8e78d2b0db12d97e0916d42ce17ad8ba3e74923e6b083cbd52bcad5afecaf4f19270c570c24dffeb0c7fd18559bbba5c
7
- data.tar.gz: 589ccc3e50fbe9856334cecc6e803c59a780d570c90f518453f042da212f0a9b0ceebce61ad30eeb86be2cfc7b5e44f288cb904c51e4eaf78cf52d2df05c731e
6
+ metadata.gz: 60d5977669c7801caea1b016ac47546e2597c7c78e291b7c216d846f076c012676b2bfced6f965d5b2de62c1ede85c22253017ef6a26fc03f9df3c0cc150ca14
7
+ data.tar.gz: 9cda0e40938c1e7e5b8d69ddd7791484fa9bda4b165306d270852eaf0f0d80d25e87ba5e97829cd862ad526590b364ef77ec1d996035e5a2d85de0bd9783a74b
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- copy_tuner_client (0.4.11)
4
+ copy_tuner_client (0.4.12)
5
5
  i18n (>= 0.5.0)
6
6
  json
7
7
 
@@ -131,6 +131,9 @@ module CopyTunerClient
131
131
  # @return [Array<Symbol>] Restrict blurb locales to upload
132
132
  attr_accessor :locales
133
133
 
134
+ # @return [Boolean] Html escape
135
+ attr_accessor :html_escape
136
+
134
137
  alias_method :secure?, :secure
135
138
 
136
139
  def copyray_js_injection_regexp_for_debug=(value)
@@ -158,6 +161,7 @@ module CopyTunerClient
158
161
  self.test_environments = %w(test cucumber)
159
162
  self.s3_host = 'copy-tuner-data-prod.s3.amazonaws.com'
160
163
  self.disable_copyray_comment_injection = false
164
+ self.html_escape = false
161
165
 
162
166
  @applied = false
163
167
  end
@@ -6,11 +6,12 @@ module CopyTunerClient
6
6
  # <!--COPYRAY views.home.index.message-->message
7
7
  def self.augment_template(source, key)
8
8
  augmented = if source.present?
9
- "<!--COPYRAY #{key}-->#{source}"
9
+ escape = CopyTunerClient.configuration.html_escape && !source.html_safe?
10
+ "<!--COPYRAY #{key}-->#{escape ? ERB::Util.html_escape(source) : source}"
10
11
  else
11
12
  source
12
13
  end
13
- ActiveSupport::SafeBuffer === source ? ActiveSupport::SafeBuffer.new(augmented) : augmented
14
+ augmented.html_safe
14
15
  end
15
16
  end
16
17
  end
@@ -28,8 +28,10 @@ module CopyTunerClient
28
28
  if CopyTunerClient.configuration.inline_translation
29
29
  content = (content.is_a?(Array) ? content : key.to_s)
30
30
  end
31
- if content.respond_to?(:html_safe)
32
- content.html_safe
31
+
32
+ if !CopyTunerClient.configuration.html_escape
33
+ # Backward compatible
34
+ content.respond_to?(:html_safe) ? content.html_safe : content
33
35
  else
34
36
  content
35
37
  end
@@ -16,7 +16,7 @@ if defined?(SimpleForm)
16
16
  defaults = object.class.lookup_ancestors.map do |klass|
17
17
  "#{attributes_scope}.#{klass.model_name.i18n_key}.#{reflection_or_attribute_name}"
18
18
  end
19
- CopyTunerClient::Copyray.augment_template(source, defaults.shift).html_safe
19
+ CopyTunerClient::Copyray.augment_template(source, defaults.shift)
20
20
  else
21
21
  source
22
22
  end
@@ -1,6 +1,6 @@
1
1
  module CopyTunerClient
2
2
  # Client version
3
- VERSION = '0.4.11'.freeze
3
+ VERSION = '0.4.12'.freeze
4
4
 
5
5
  # API version being used to communicate with the server
6
6
  API_VERSION = '2.0'.freeze
@@ -0,0 +1,56 @@
1
+ require 'spec_helper'
2
+ require 'copy_tuner_client/copyray'
3
+
4
+ describe CopyTunerClient::Copyray do
5
+ describe '.augment_template' do
6
+ subject { CopyTunerClient::Copyray.augment_template(source, key) }
7
+
8
+ let(:key) { 'en.test.key' }
9
+
10
+ shared_examples 'Not escaped' do
11
+ it { is_expected.to be_html_safe }
12
+ it { is_expected.to eq "<!--COPYRAY #{key}--><b>Hello</b>" }
13
+ end
14
+
15
+ context 'html_escape option is false' do
16
+ before do
17
+ CopyTunerClient.configure do |configuration|
18
+ configuration.html_escape = false
19
+ end
20
+ end
21
+
22
+ context 'string not marked as html safe' do
23
+ let(:source) { FakeHtmlSafeString.new('<b>Hello</b>') }
24
+
25
+ it_behaves_like 'Not escaped'
26
+ end
27
+
28
+ context 'string marked as html safe' do
29
+ let(:source) { FakeHtmlSafeString.new('<b>Hello</b>').html_safe }
30
+
31
+ it_behaves_like 'Not escaped'
32
+ end
33
+ end
34
+
35
+ context 'html_escape option is true' do
36
+ before do
37
+ CopyTunerClient.configure do |configuration|
38
+ configuration.html_escape = true
39
+ end
40
+ end
41
+
42
+ context 'string not marked as html safe' do
43
+ let(:source) { FakeHtmlSafeString.new('<b>Hello</b>') }
44
+
45
+ it { is_expected.to be_html_safe }
46
+ it { is_expected.to eq "<!--COPYRAY #{key}-->&lt;b&gt;Hello&lt;/b&gt;" }
47
+ end
48
+
49
+ context 'string marked as html safe' do
50
+ let(:source) { FakeHtmlSafeString.new('<b>Hello</b>').html_safe }
51
+
52
+ it_behaves_like 'Not escaped'
53
+ end
54
+ end
55
+ end
56
+ end
@@ -124,6 +124,20 @@ describe CopyTunerClient::I18nBackend do
124
124
  to eq('Expected')
125
125
  end
126
126
 
127
+ context "html_escape option is true" do
128
+ before do
129
+ CopyTunerClient.configure do |configuration|
130
+ configuration.html_escape = true
131
+ end
132
+ end
133
+
134
+ it "do not marks strings as html safe" do
135
+ cache['en.test.key'] = FakeHtmlSafeString.new("Hello")
136
+ backend = build_backend
137
+ expect(backend.translate('en', 'test.key')).not_to be_html_safe
138
+ end
139
+ end
140
+
127
141
  describe "with stored translations" do
128
142
  subject { build_backend }
129
143
 
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: copy_tuner_client
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.4.11
4
+ version: 0.4.12
5
5
  platform: ruby
6
6
  authors:
7
7
  - SonicGarden
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2018-07-27 00:00:00.000000000 Z
11
+ date: 2019-05-22 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: i18n
@@ -262,6 +262,7 @@ files:
262
262
  - spec/copy_tuner_client/cache_spec.rb
263
263
  - spec/copy_tuner_client/client_spec.rb
264
264
  - spec/copy_tuner_client/configuration_spec.rb
265
+ - spec/copy_tuner_client/copyray_spec.rb
265
266
  - spec/copy_tuner_client/i18n_backend_spec.rb
266
267
  - spec/copy_tuner_client/poller_spec.rb
267
268
  - spec/copy_tuner_client/prefixed_logger_spec.rb
@@ -319,6 +320,7 @@ test_files:
319
320
  - spec/copy_tuner_client/cache_spec.rb
320
321
  - spec/copy_tuner_client/client_spec.rb
321
322
  - spec/copy_tuner_client/configuration_spec.rb
323
+ - spec/copy_tuner_client/copyray_spec.rb
322
324
  - spec/copy_tuner_client/i18n_backend_spec.rb
323
325
  - spec/copy_tuner_client/poller_spec.rb
324
326
  - spec/copy_tuner_client/prefixed_logger_spec.rb