threedaymonk-l10nizer 0.0.5 → 0.0.6

Sign up to get free protection for your applications and to get access to all the features.
@@ -27,7 +27,13 @@ module L10nizer
27
27
 
28
28
  def make_safe(string)
29
29
  return nil if string.nil?
30
- safe = string.downcase.gsub(/[^a-z0-9]+/, "_").gsub(/^_|_$/, "")[0, 40]
30
+ safe = string.
31
+ downcase.
32
+ gsub(/&[a-z0-9]{1,20};/, ""). # entities
33
+ gsub(/<[^>]*>/, ""). # html
34
+ gsub(/[^a-z0-9]+/, "_"). # non alphanumeric
35
+ slice(0, 40).
36
+ gsub(/^_|_$/, "") # leading/trailing _
31
37
  safe = "unknown" if safe.empty?
32
38
  safe
33
39
  end
@@ -2,7 +2,7 @@ module L10nizer #:nodoc:
2
2
  module VERSION #:nodoc:
3
3
  MAJOR = 0
4
4
  MINOR = 0
5
- TINY = 5
5
+ TINY = 6
6
6
 
7
7
  STRING = [MAJOR, MINOR, TINY].join('.')
8
8
  end
@@ -17,7 +17,7 @@ class KeyGeneratorTest < Test::Unit::TestCase
17
17
 
18
18
  should "truncate exceptionally long keys" do
19
19
  long = "blah_" * 20
20
- short = long[0, 40]
20
+ short = "blah_blah_blah_blah_blah_blah_blah_blah"
21
21
  assert_equal short, @keygen.call(long)
22
22
  end
23
23
 
@@ -31,9 +31,17 @@ class KeyGeneratorTest < Test::Unit::TestCase
31
31
  assert_equal "a_thing_2", @keygen.call("A Thing")
32
32
  end
33
33
 
34
- should "generate_non_empty_keys_for_punctuation" do
34
+ should "generate non empty keys for punctuation" do
35
35
  assert_not_equal "", @keygen.call("<>!@#%#.,")
36
36
  end
37
+
38
+ should "skip entities in keys" do
39
+ assert_equal "foo_bar", @keygen.call("foo &apos; bar")
40
+ end
41
+
42
+ should "skip inline markup in keys" do
43
+ assert_equal "foo_bar", @keygen.call("foo <strong>bar</strong>")
44
+ end
37
45
  end
38
46
 
39
47
  context "with namespacing" do
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: threedaymonk-l10nizer
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.5
4
+ version: 0.0.6
5
5
  platform: ruby
6
6
  authors:
7
7
  - Paul Battley