hache 1.0.0 → 1.1.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 798b7e68ce464d0abd7473ab0e74d03f1d2f534a
4
- data.tar.gz: 7dea00c366e428e3006cb7542909c32e37cc0d03
3
+ metadata.gz: 0b9f5c147e9e42d09d6542a90d5078fda2dae3e6
4
+ data.tar.gz: 0a40d7774cbd300f116e9ffc66124592833589dc
5
5
  SHA512:
6
- metadata.gz: 02aba9da7b52e260723143789303478823df69f28ed0bc9babe173b1915802cc599ee762b1fa5dabf52c0732fd52011ec5406416b012a5c7d13fa07f74071815
7
- data.tar.gz: 097dae04d84e9911c40f96b747ef764350fa7f170d786fe816c01c8f2721666bb854deed0e9882bd8ba31135d1110c0a5fc2839683a5783537faf09f178baa1f
6
+ metadata.gz: 9089048bab221a9b99ea953cf2955e19394c2ccbe07c422cb4780c392f330fed13f0a97245a7b094a078e03aa1ba51eb2f7009969ef4ba2eb6c14b6620218494
7
+ data.tar.gz: 84bce11cf3bf4977504b05e0a726f9c93213cafc927d48d11a05ee40cf6bd137cd1ea952a207fc93de9c94582800df341bee30fc70a8c5cb3c1d5c7b6215358e
@@ -0,0 +1,20 @@
1
+ require "benchmark/ips"
2
+ require "rack/utils"
3
+ require_relative "../lib/hache"
4
+
5
+ text = %q(some < text > inside & these " escapable' characters/1234)
6
+
7
+ Benchmark.ips do |x|
8
+ x.report("encode") { text.encode(xml: :text) } # encode doesn't escape `'`, `"` and `/`.
9
+ x.report("rack") { Rack::Utils.escape_html(text) }
10
+ x.report("hache") { Hache.h(text) }
11
+ end
12
+
13
+ # Calculating -------------------------------------
14
+ # encode 16385 i/100ms
15
+ # rack 9626 i/100ms
16
+ # hache 10211 i/100ms
17
+ # -------------------------------------------------
18
+ # encode 241085.8 (±11.8%) i/s - 1163335 in 5.004123s
19
+ # rack 127905.8 (±4.5%) i/s - 644942 in 5.053418s
20
+ # hache 153666.9 (±11.5%) i/s - 745403 in 5.056082s
data/hache.gemspec CHANGED
@@ -1,6 +1,6 @@
1
1
  Gem::Specification.new do |s|
2
2
  s.name = "hache"
3
- s.version = "1.0.0"
3
+ s.version = "1.1.0"
4
4
  s.summary = %q(Escapes HTML tag characters: &, <>, ", ', /.)
5
5
  s.description = s.summary
6
6
  s.authors = ["Francesco Rodríguez"]
data/lib/hache.rb CHANGED
@@ -10,7 +10,7 @@ module Hache
10
10
 
11
11
  UNSAFE = /[&"'><\/]/
12
12
 
13
- def self.h(str)
14
- str.to_s.gsub(UNSAFE, HTML_ESCAPE)
13
+ def self.h(s)
14
+ s.to_str.gsub(UNSAFE, HTML_ESCAPE)
15
15
  end
16
16
  end
data/test/hache.rb CHANGED
@@ -1,18 +1,10 @@
1
1
  require "cutest"
2
2
  require_relative "../lib/hache"
3
3
 
4
- def h(str)
5
- Hache.h(str)
6
- end
7
-
8
4
  test "not escapes safe string" do
9
- assert_equal "hola", h("hola")
10
- end
11
-
12
- test "not raises an error with nil values" do
13
- assert_equal "", h(nil)
5
+ assert_equal "hola", Hache.h("hola")
14
6
  end
15
7
 
16
8
  test "escapes unsafe characters" do
17
- assert_equal "&lt;&gt;&amp;&quot;&#x27;&#x2F;", h(%q(<>&"'/))
9
+ assert_equal "&lt;&gt;&amp;&quot;&#x27;&#x2F;", Hache.h(%q(<>&"'/))
18
10
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: hache
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.0
4
+ version: 1.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Francesco Rodríguez
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-03-28 00:00:00.000000000 Z
11
+ date: 2014-03-31 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: cutest
@@ -34,6 +34,7 @@ files:
34
34
  - .gems
35
35
  - LICENSE
36
36
  - README.md
37
+ - benchmarks/escaping.rb
37
38
  - hache.gemspec
38
39
  - lib/hache.rb
39
40
  - test/hache.rb