copy_tuner_client 0.4.11 → 0.4.12
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Gemfile.lock +1 -1
- data/lib/copy_tuner_client/configuration.rb +4 -0
- data/lib/copy_tuner_client/copyray.rb +3 -2
- data/lib/copy_tuner_client/i18n_backend.rb +4 -2
- data/lib/copy_tuner_client/simple_form_extention.rb +1 -1
- data/lib/copy_tuner_client/version.rb +1 -1
- data/spec/copy_tuner_client/copyray_spec.rb +56 -0
- data/spec/copy_tuner_client/i18n_backend_spec.rb +14 -0
- metadata +4 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 065504cc3f7dfc961ad953d04a27337c74e54adb
|
4
|
+
data.tar.gz: bb3a4c5e3d9b3915b7564aea2a086a353069d2de
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 60d5977669c7801caea1b016ac47546e2597c7c78e291b7c216d846f076c012676b2bfced6f965d5b2de62c1ede85c22253017ef6a26fc03f9df3c0cc150ca14
|
7
|
+
data.tar.gz: 9cda0e40938c1e7e5b8d69ddd7791484fa9bda4b165306d270852eaf0f0d80d25e87ba5e97829cd862ad526590b364ef77ec1d996035e5a2d85de0bd9783a74b
|
data/Gemfile.lock
CHANGED
@@ -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
|
-
|
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
|
-
|
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
|
-
|
32
|
-
|
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)
|
19
|
+
CopyTunerClient::Copyray.augment_template(source, defaults.shift)
|
20
20
|
else
|
21
21
|
source
|
22
22
|
end
|
@@ -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}--><b>Hello</b>" }
|
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.
|
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:
|
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
|