walters 0.0.1 → 0.1.0
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.
- data/LICENSE +1 -15
- data/README.md +37 -5
- data/Rakefile +65 -0
- data/lib/walters/html/cgi.rb +12 -0
- data/lib/walters/html/erb.rb +13 -0
- data/lib/walters/html/haml.rb +10 -0
- data/lib/walters/html/html_safety.rb +19 -0
- data/lib/walters/html/rack.rb +11 -0
- data/lib/walters/javascript/action_view.rb +11 -0
- data/lib/walters/version.rb +1 -1
- data/lib/walters/walters.rb +22 -86
- data/lib/walters/walters_xni.rb +109 -0
- data/spec/spec_helper.rb +8 -0
- data/spec/walters/html_escape_spec.rb +58 -0
- data/spec/walters/javascript_escape_spec.rb +49 -0
- data/walters.gemspec +2 -2
- data/{ext → xni-ext}/Rakefile +1 -1
- data/{ext → xni-ext}/houdini/buffer.c +0 -0
- data/{ext → xni-ext}/houdini/buffer.h +0 -0
- data/{ext → xni-ext}/houdini/houdini.h +0 -0
- data/{ext → xni-ext}/houdini/houdini_href_e.c +0 -0
- data/{ext → xni-ext}/houdini/houdini_html_e.c +0 -0
- data/{ext → xni-ext}/houdini/houdini_html_u.c +0 -0
- data/{ext → xni-ext}/houdini/houdini_js_e.c +0 -0
- data/{ext → xni-ext}/houdini/houdini_js_u.c +0 -0
- data/{ext → xni-ext}/houdini/houdini_uri_e.c +0 -0
- data/{ext → xni-ext}/houdini/houdini_uri_u.c +0 -0
- data/{ext → xni-ext}/houdini/houdini_xml_e.c +0 -0
- data/{ext → xni-ext}/houdini/html_unescape.h +0 -0
- data/{ext → xni-ext}/walters.cpp +19 -1
- data/{ext → xni-ext}/walters_buffer.cpp +19 -1
- data/{ext/x86_64-darwin/__xni_walters.cpp → xni-ext/x86_64-darwin/__xni_walters_xni.cpp} +1 -1
- data/{ext/x86_64-darwin/walters.h → xni-ext/x86_64-darwin/walters_xni.h} +3 -3
- metadata +30 -20
data/LICENSE
CHANGED
@@ -11,18 +11,4 @@
|
|
11
11
|
limitations under the License.
|
12
12
|
|
13
13
|
|
14
|
-
|
15
|
-
the terms of the GNU Lesser General Public License as published by
|
16
|
-
the Free Software Foundation, either version 3 of the License, or
|
17
|
-
(at your option) any later version.
|
18
|
-
|
19
|
-
This code is distributed in the hope that it will be useful, but WITHOUT
|
20
|
-
ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
21
|
-
FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License
|
22
|
-
version 3 for more details.
|
23
|
-
|
24
|
-
You should have received a copy of the GNU Lesser General Public License
|
25
|
-
version 3 along with this work. If not, see <http://www.gnu.org/licenses/>.
|
26
|
-
|
27
|
-
|
28
|
-
|
14
|
+
This software also contains code licensed under the GNU General Public License version 2 with a linking exception.
|
data/README.md
CHANGED
@@ -1,10 +1,11 @@
|
|
1
1
|
walters [](https://travis-ci.org/wmeissner/walters)
|
2
2
|
======
|
3
3
|
|
4
|
-
[Walters](https://github.com/wmeissner/walters) is a
|
5
|
-
html escaping library
|
4
|
+
[Walters](https://github.com/wmeissner/walters) is a fast HTML (and href, uri, xml, javascript) escaping library for JRuby.
|
6
5
|
|
7
|
-
|
6
|
+
It is optimised for the non-escaping case - i.e. where the input string contains no characters requiring escaping.
|
7
|
+
|
8
|
+
### Example usage
|
8
9
|
|
9
10
|
jruby-1.7.4.dev :001 > require 'walters'
|
10
11
|
=> true
|
@@ -12,9 +13,40 @@ html escaping library
|
|
12
13
|
=> "<html>"
|
13
14
|
|
14
15
|
|
15
|
-
The same extension can be used from the legacy CRuby VM
|
16
|
+
The same extension can also be used from the legacy CRuby VM for compatibility.
|
16
17
|
|
17
18
|
2.0.0p0 :001 > require 'walters'
|
18
19
|
=> true
|
19
20
|
2.0.0p0 :002 > Walters.escape_html('<html>')
|
20
|
-
=> "<html>"
|
21
|
+
=> "<html>"
|
22
|
+
|
23
|
+
### Benchmarks
|
24
|
+
Escaping 1000 bytes of text requiring escaping 1000000 times under jruby-1.7.4:
|
25
|
+
|
26
|
+
user system total real
|
27
|
+
Rack::Utils.escape_html 89.980000 0.230000 90.210000 ( 90.272000)
|
28
|
+
Haml::Helpers.html_escape 50.420000 0.170000 50.590000 ( 51.147000)
|
29
|
+
ERB::Util.html_escape 44.650000 0.130000 44.780000 ( 45.518000)
|
30
|
+
CGI.escapeHTML 36.230000 0.090000 36.320000 ( 36.358000)
|
31
|
+
String#gsub 35.490000 0.090000 35.580000 ( 35.587000)
|
32
|
+
Walters.escape_html 10.090000 0.030000 10.120000 ( 10.126000)
|
33
|
+
|
34
|
+
Escaping 1000 bytes of html-free text 1000000 times under jruby-1.7.4:
|
35
|
+
|
36
|
+
user system total real
|
37
|
+
Rack::Utils.escape_html 3.530000 0.010000 3.540000 ( 3.601000)
|
38
|
+
Haml::Helpers.html_escape 4.140000 0.010000 4.150000 ( 4.196000)
|
39
|
+
ERB::Util.html_escape 11.710000 0.030000 11.740000 ( 11.876000)
|
40
|
+
CGI.escapeHTML 3.440000 0.010000 3.450000 ( 3.548000)
|
41
|
+
String#gsub 3.470000 0.000000 3.470000 ( 3.531000)
|
42
|
+
Walters.escape_html 0.660000 0.010000 0.670000 ( 0.663000)
|
43
|
+
|
44
|
+
### Punching ducks
|
45
|
+
There are monkey-patching shims supplied that replace common html escaping functions with calls to the Walters escape_html function.
|
46
|
+
|
47
|
+
e.g. to patch Rack::Utils.escape_html to use Walters.escape_html:
|
48
|
+
|
49
|
+
require 'walters/html/rack'
|
50
|
+
|
51
|
+
### Credits
|
52
|
+
The escaping routines are based on C code from the [Houdini](https://github.com/vmg/houdini) project, and the specs, benchmarks and monkey patches come from the [escape_utils](https://github.com/brianmario/escape_utils) project
|
data/Rakefile
CHANGED
@@ -1,6 +1,71 @@
|
|
1
1
|
require 'rake/clean'
|
2
|
+
require 'rubygems/package_task'
|
2
3
|
require 'rubygems/tasks'
|
3
4
|
|
5
|
+
|
6
|
+
def gem_spec
|
7
|
+
@gem_spec ||= Gem::Specification.load('walters.gemspec')
|
8
|
+
end
|
9
|
+
|
10
|
+
TEST_DEPS = []
|
11
|
+
if defined?(JRUBY_VERSION)
|
12
|
+
require 'ant'
|
13
|
+
jar_file = 'lib/walters/walters_ext.jar'
|
14
|
+
CLEAN.include jar_file
|
15
|
+
TEST_DEPS << jar_file
|
16
|
+
|
17
|
+
gem_spec.files << jar_file
|
18
|
+
|
19
|
+
directory 'pkg/classes'
|
20
|
+
CLEAN.include 'pkg/classes'
|
21
|
+
|
22
|
+
desc 'Compile the JRuby extension'
|
23
|
+
task :compile => FileList['pkg/classes', 'jruby-ext/src/**/*.java'] do |t|
|
24
|
+
ant.javac :srcdir => 'jruby-ext/src', :destdir => t.prerequisites.first,
|
25
|
+
:source => '1.6', :target => '1.6', :debug => true, :includeantruntime => false,
|
26
|
+
:classpath => '${java.class.path}:${sun.boot.class.path}'
|
27
|
+
end
|
28
|
+
|
29
|
+
desc 'Build the jar'
|
30
|
+
file jar_file => :compile do |t|
|
31
|
+
ant.jar :basedir => 'pkg/classes', :destfile => t.name, :includes => '**/*.class'
|
32
|
+
end
|
33
|
+
|
34
|
+
task :jar => jar_file
|
35
|
+
end
|
36
|
+
|
4
37
|
Gem::Tasks.new do |t|
|
5
38
|
t.scm.tag.format = '%s'
|
6
39
|
end
|
40
|
+
|
41
|
+
task :specs do
|
42
|
+
sh %{#{Gem.ruby} -w -Ilib -S rspec spec}
|
43
|
+
end
|
44
|
+
|
45
|
+
namespace 'java' do
|
46
|
+
java_gem_spec = Gem::Specification.new do |s|
|
47
|
+
s.name = gem_spec.name
|
48
|
+
s.version = gem_spec.version
|
49
|
+
s.author = gem_spec.author
|
50
|
+
s.email = gem_spec.email
|
51
|
+
s.homepage = gem_spec.homepage
|
52
|
+
s.summary = gem_spec.summary
|
53
|
+
s.description = gem_spec.description
|
54
|
+
s.files = %w(LICENSE LICENSE-EscapeUtils.txt LICENSE-houdini.txt README.md Rakefile)
|
55
|
+
s.files << Dir['{lib,spec,benchmark}/**/*.rb']
|
56
|
+
s.files << 'lib/walters/walters_ext.jar'
|
57
|
+
s.has_rdoc = false
|
58
|
+
s.license = gem_spec.license
|
59
|
+
s.platform = 'java'
|
60
|
+
end
|
61
|
+
|
62
|
+
Gem::PackageTask.new(java_gem_spec) do |pkg|
|
63
|
+
pkg.need_zip = true
|
64
|
+
pkg.need_tar = true
|
65
|
+
pkg.package_dir = 'pkg'
|
66
|
+
end
|
67
|
+
|
68
|
+
task :gem => 'lib/walters/walters_ext.jar'
|
69
|
+
end
|
70
|
+
|
71
|
+
task 'gem:java' => 'java:gem'
|
@@ -0,0 +1,12 @@
|
|
1
|
+
# This file contains code based on the EscapeUtils project. See the file LICENSE-EscapeUtils.txt for details.
|
2
|
+
require_relative 'html_safety'
|
3
|
+
|
4
|
+
module CGI
|
5
|
+
extend ::Walters::HtmlSafety
|
6
|
+
extend ::Walters::HtmlUnescape
|
7
|
+
|
8
|
+
class << self
|
9
|
+
alias escapeHTML walters_escape_html
|
10
|
+
alias unescapeHTML walters_unescape_html
|
11
|
+
end
|
12
|
+
end
|
@@ -0,0 +1,13 @@
|
|
1
|
+
# This file contains code based on the EscapeUtils project. See the file LICENSE-EscapeUtils.txt for details.
|
2
|
+
require_relative 'html_safety'
|
3
|
+
|
4
|
+
class ERB
|
5
|
+
module Util
|
6
|
+
include ::Walters::HtmlSafety
|
7
|
+
|
8
|
+
alias html_escape walters_escape_html
|
9
|
+
alias h html_escape
|
10
|
+
module_function :h
|
11
|
+
module_function :html_escape
|
12
|
+
end
|
13
|
+
end
|
@@ -0,0 +1,10 @@
|
|
1
|
+
# This file contains code based on the EscapeUtils project. See the file LICENSE-EscapeUtils.txt for details.
|
2
|
+
require_relative 'html_safety'
|
3
|
+
|
4
|
+
module Haml
|
5
|
+
module Helpers
|
6
|
+
include ::Walters::HtmlSafety
|
7
|
+
|
8
|
+
alias html_escape walters_escape_html
|
9
|
+
end
|
10
|
+
end
|
@@ -0,0 +1,19 @@
|
|
1
|
+
# This file contains code based on the EscapeUtils project. See the file LICENSE-EscapeUtils.txt for details.
|
2
|
+
require 'walters'
|
3
|
+
|
4
|
+
module Walters
|
5
|
+
module HtmlSafety
|
6
|
+
if ''.respond_to? :html_safe?
|
7
|
+
def walters_escape_html(s)
|
8
|
+
if s.html_safe?
|
9
|
+
s.to_s.html_safe
|
10
|
+
else
|
11
|
+
Walters.escape_html(s).html_safe
|
12
|
+
end
|
13
|
+
end
|
14
|
+
else
|
15
|
+
include ::Walters::HtmlEscape
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
19
|
+
end
|
@@ -0,0 +1,11 @@
|
|
1
|
+
# This file contains code based on the EscapeUtils project. See the file LICENSE-EscapeUtils.txt for details.
|
2
|
+
require_relative 'html_safety'
|
3
|
+
|
4
|
+
module Rack
|
5
|
+
module Utils
|
6
|
+
include ::Walters::HtmlSafety
|
7
|
+
|
8
|
+
alias escape_html walters_escape_html
|
9
|
+
module_function :escape_html
|
10
|
+
end
|
11
|
+
end
|
@@ -0,0 +1,11 @@
|
|
1
|
+
# This file contains code based on the EscapeUtils project. See the file LICENSE-EscapeUtils.txt for details.
|
2
|
+
require 'walters'
|
3
|
+
|
4
|
+
module ActionView
|
5
|
+
module Helpers
|
6
|
+
module JavaScriptHelper
|
7
|
+
include ::Walters::JavaScriptEscape
|
8
|
+
alias escape_javascript walters_escape_javascript
|
9
|
+
end
|
10
|
+
end
|
11
|
+
end
|
data/lib/walters/version.rb
CHANGED
data/lib/walters/walters.rb
CHANGED
@@ -1,87 +1,23 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
native :unescape_js, [ :cstring, :uint], :bool
|
24
|
-
end
|
25
|
-
|
26
|
-
native :free_cstring, [ :pointer ], :void
|
27
|
-
native :read_cstring, [ :pointer ], :cstring
|
28
|
-
native :_escape_html, [ :cstring, :uint, :bool], :pointer
|
29
|
-
native :_unescape_html, [ :cstring, :uint], :pointer
|
30
|
-
native :_escape_xml, [ :cstring, :uint], :pointer
|
31
|
-
native :_escape_uri, [ :cstring, :uint], :pointer
|
32
|
-
native :_escape_url, [ :cstring, :uint], :pointer
|
33
|
-
native :_escape_href, [ :cstring, :uint], :pointer
|
34
|
-
native :_unescape_uri, [ :cstring, :uint], :pointer
|
35
|
-
native :_unescape_url, [ :cstring, :uint], :pointer
|
36
|
-
native :_escape_js, [ :cstring, :uint], :pointer
|
37
|
-
native :_unescape_js, [ :cstring, :uint], :pointer
|
38
|
-
|
39
|
-
class << self
|
40
|
-
private
|
41
|
-
def cstring(ptr, str)
|
42
|
-
ptr ? read_cstring(ptr) : str
|
43
|
-
ensure
|
44
|
-
free_cstring(ptr) if ptr
|
45
|
-
end
|
46
|
-
end
|
47
|
-
|
48
|
-
def self.escape_html(src, secure = true)
|
49
|
-
cstring _escape_html(src, src.length, secure), src
|
50
|
-
end
|
51
|
-
|
52
|
-
def self.unescape_html(src)
|
53
|
-
cstring _unescape_html(src, src.length), src
|
54
|
-
end
|
55
|
-
|
56
|
-
def self.escape_xml(src)
|
57
|
-
cstring _escape_xml(src, src.length, secure), src
|
58
|
-
end
|
59
|
-
|
60
|
-
def self.escape_uri(src)
|
61
|
-
cstring _escape_uri(src, src.length, secure), src
|
62
|
-
end
|
63
|
-
|
64
|
-
def self.escape_url(src)
|
65
|
-
cstring _escape_url(src, src.length, secure), src
|
66
|
-
end
|
67
|
-
|
68
|
-
def self.escape_href(src)
|
69
|
-
cstring _escape_href(src, src.length, secure), src
|
70
|
-
end
|
71
|
-
|
72
|
-
def self.unescape_uri(src)
|
73
|
-
cstring _unescape_uri(src, src.length), src
|
74
|
-
end
|
75
|
-
|
76
|
-
def self.unescape_url(src)
|
77
|
-
cstring _unescape_url(src, src.length), src
|
78
|
-
end
|
79
|
-
|
80
|
-
def self.escape_js(src)
|
81
|
-
cstring _escape_js(src, src.length, secure), src
|
82
|
-
end
|
83
|
-
|
84
|
-
def self.unescape_js(src)
|
85
|
-
cstring _unescape_js(src, src.length), src
|
86
|
-
end
|
1
|
+
#
|
2
|
+
# Copyright (C) 2013 Wayne Meissner
|
3
|
+
#
|
4
|
+
# This file is part of the Walters project (http://github.com/wmeissner/walters).
|
5
|
+
#
|
6
|
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
7
|
+
# you may not use this file except in compliance with the License.
|
8
|
+
# You may obtain a copy of the License at
|
9
|
+
#
|
10
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
11
|
+
#
|
12
|
+
# Unless required by applicable law or agreed to in writing, software
|
13
|
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
14
|
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
15
|
+
# See the License for the specific language governing permissions and
|
16
|
+
# limitations under the License.
|
17
|
+
|
18
|
+
|
19
|
+
if defined?(JRUBY_VERSION)
|
20
|
+
require 'walters/walters_ext'
|
21
|
+
else
|
22
|
+
require_relative 'walters_xni'
|
87
23
|
end
|
@@ -0,0 +1,109 @@
|
|
1
|
+
#
|
2
|
+
# Copyright (C) 2013 Wayne Meissner
|
3
|
+
#
|
4
|
+
# This file is part of the Walters project (http://github.com/wmeissner/walters).
|
5
|
+
#
|
6
|
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
7
|
+
# you may not use this file except in compliance with the License.
|
8
|
+
# You may obtain a copy of the License at
|
9
|
+
#
|
10
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
11
|
+
#
|
12
|
+
# Unless required by applicable law or agreed to in writing, software
|
13
|
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
14
|
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
15
|
+
# See the License for the specific language governing permissions and
|
16
|
+
# limitations under the License.
|
17
|
+
|
18
|
+
require 'xni'
|
19
|
+
|
20
|
+
module Walters
|
21
|
+
extend XNI::Extension
|
22
|
+
extension 'walters'
|
23
|
+
|
24
|
+
class Buffer < XNI::DataObject
|
25
|
+
custom_finalizer
|
26
|
+
|
27
|
+
native :initialize, [ :uint ], :void
|
28
|
+
native :cstring, [], :cstring
|
29
|
+
|
30
|
+
native :escape_html, [ :cstring, :uint], :bool
|
31
|
+
native :escape_html0, [ :cstring, :uint, :bool ], :bool
|
32
|
+
native :unescape_html, [ :cstring, :uint], :bool
|
33
|
+
native :escape_xml, [ :cstring, :uint], :bool
|
34
|
+
native :escape_uri, [ :cstring, :uint], :bool
|
35
|
+
native :escape_url, [ :cstring, :uint], :bool
|
36
|
+
native :escape_href, [ :cstring, :uint], :bool
|
37
|
+
native :unescape_uri, [ :cstring, :uint], :bool
|
38
|
+
native :unescape_url, [ :cstring, :uint], :bool
|
39
|
+
native :escape_js, [ :cstring, :uint], :bool
|
40
|
+
native :unescape_js, [ :cstring, :uint], :bool
|
41
|
+
end
|
42
|
+
|
43
|
+
native :free_cstring, [ :pointer ], :void
|
44
|
+
native :read_cstring, [ :pointer ], :cstring
|
45
|
+
native :_escape_html, [ :cstring, :uint, :bool], :pointer
|
46
|
+
native :_unescape_html, [ :cstring, :uint], :pointer
|
47
|
+
native :_escape_xml, [ :cstring, :uint], :pointer
|
48
|
+
native :_escape_uri, [ :cstring, :uint], :pointer
|
49
|
+
native :_escape_url, [ :cstring, :uint], :pointer
|
50
|
+
native :_escape_href, [ :cstring, :uint], :pointer
|
51
|
+
native :_unescape_uri, [ :cstring, :uint], :pointer
|
52
|
+
native :_unescape_url, [ :cstring, :uint], :pointer
|
53
|
+
native :_escape_js, [ :cstring, :uint], :pointer
|
54
|
+
native :_unescape_js, [ :cstring, :uint], :pointer
|
55
|
+
|
56
|
+
class << self
|
57
|
+
private
|
58
|
+
def cstring(ptr, str)
|
59
|
+
if ptr
|
60
|
+
begin
|
61
|
+
str = read_cstring(ptr)
|
62
|
+
ensure
|
63
|
+
free_cstring(ptr)
|
64
|
+
end
|
65
|
+
end
|
66
|
+
str
|
67
|
+
end
|
68
|
+
end
|
69
|
+
|
70
|
+
def self.escape_html(src, secure = true)
|
71
|
+
cstring _escape_html(src, src.length, secure), src
|
72
|
+
end
|
73
|
+
|
74
|
+
def self.unescape_html(src)
|
75
|
+
cstring _unescape_html(src, src.length), src
|
76
|
+
end
|
77
|
+
|
78
|
+
def self.escape_xml(src)
|
79
|
+
cstring _escape_xml(src, src.length), src
|
80
|
+
end
|
81
|
+
|
82
|
+
def self.escape_uri(src)
|
83
|
+
cstring _escape_uri(src, src.length), src
|
84
|
+
end
|
85
|
+
|
86
|
+
def self.escape_url(src)
|
87
|
+
cstring _escape_url(src, src.length), src
|
88
|
+
end
|
89
|
+
|
90
|
+
def self.escape_href(src)
|
91
|
+
cstring _escape_href(src, src.length), src
|
92
|
+
end
|
93
|
+
|
94
|
+
def self.unescape_uri(src)
|
95
|
+
cstring _unescape_uri(src, src.length), src
|
96
|
+
end
|
97
|
+
|
98
|
+
def self.unescape_url(src)
|
99
|
+
cstring _unescape_url(src, src.length), src
|
100
|
+
end
|
101
|
+
|
102
|
+
def self.escape_js(src)
|
103
|
+
cstring _escape_js(src, src.length), src
|
104
|
+
end
|
105
|
+
|
106
|
+
def self.unescape_js(src)
|
107
|
+
cstring _unescape_js(src, src.length), src
|
108
|
+
end
|
109
|
+
end
|
data/spec/spec_helper.rb
ADDED
@@ -0,0 +1,58 @@
|
|
1
|
+
# encoding: UTF-8
|
2
|
+
#
|
3
|
+
# Copyright (C) 2013 Wayne Meissner
|
4
|
+
#
|
5
|
+
# This file is part of the Walters project (http://github.com/wmeissner/walters).
|
6
|
+
#
|
7
|
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
8
|
+
# you may not use this file except in compliance with the License.
|
9
|
+
# You may obtain a copy of the License at
|
10
|
+
#
|
11
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
12
|
+
#
|
13
|
+
# Unless required by applicable law or agreed to in writing, software
|
14
|
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
15
|
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
16
|
+
# See the License for the specific language governing permissions and
|
17
|
+
# limitations under the License.
|
18
|
+
#
|
19
|
+
# This file contains code based on the EscapeUtils project. See the file LICENSE-EscapeUtils.txt for details.
|
20
|
+
#
|
21
|
+
|
22
|
+
require File.expand_path('../../spec_helper.rb', __FILE__)
|
23
|
+
|
24
|
+
describe 'html escape' do
|
25
|
+
it 'double quotes' do
|
26
|
+
Walters.escape_html("<some_tag some_attr=\"some value\"/>").should == '<some_tag some_attr="some value"/>'
|
27
|
+
end
|
28
|
+
|
29
|
+
it 'single quotes' do
|
30
|
+
Walters.escape_html("<some_tag some_attr='some value'/>").should == '<some_tag some_attr='some value'/>'
|
31
|
+
end
|
32
|
+
|
33
|
+
it 'ampersand' do
|
34
|
+
Walters.escape_html('<b>Bourbon & Branch</b>').should == '<b>Bourbon & Branch</b>'
|
35
|
+
end
|
36
|
+
|
37
|
+
it 'original returned if no escaping required' do
|
38
|
+
str = 'foobar'
|
39
|
+
Walters.escape_html(str).should equal str
|
40
|
+
end
|
41
|
+
|
42
|
+
it 'all tags escaped' do
|
43
|
+
Walters.escape_html('&<>"\'/').should == '&<>"'/'
|
44
|
+
end
|
45
|
+
|
46
|
+
it 'plain text followed by tag' do
|
47
|
+
Walters.escape_html('foobar<1>').should == 'foobar<1>'
|
48
|
+
end
|
49
|
+
|
50
|
+
it 'non-utf8 input' do
|
51
|
+
lambda { Walters.escape_html('<b>Bourbon & Branch</b>'.encode('ISO-8859-1')) }.should raise_error Encoding::CompatibilityError
|
52
|
+
end
|
53
|
+
|
54
|
+
it 'returned value has same encoding as original' do
|
55
|
+
str = '<b>Bourbon & Branch</b>'.encode('utf-8')
|
56
|
+
Walters.escape_html(str).encoding.should == str.encoding
|
57
|
+
end
|
58
|
+
end
|
@@ -0,0 +1,49 @@
|
|
1
|
+
# encoding: UTF-8
|
2
|
+
#
|
3
|
+
# Copyright (C) 2013 Wayne Meissner
|
4
|
+
#
|
5
|
+
# This file is part of the Walters project (http://github.com/wmeissner/walters).
|
6
|
+
#
|
7
|
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
8
|
+
# you may not use this file except in compliance with the License.
|
9
|
+
# You may obtain a copy of the License at
|
10
|
+
#
|
11
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
12
|
+
#
|
13
|
+
# Unless required by applicable law or agreed to in writing, software
|
14
|
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
15
|
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
16
|
+
# See the License for the specific language governing permissions and
|
17
|
+
# limitations under the License.
|
18
|
+
#
|
19
|
+
# This file contains code based on the EscapeUtils project. See the file LICENSE-EscapeUtils.txt for details.
|
20
|
+
#
|
21
|
+
|
22
|
+
describe 'javascript' do
|
23
|
+
it 'quotes and newlines' do
|
24
|
+
Walters.escape_javascript(%(This "thing" is really\n netos\r\n\n')).should == %(This \\"thing\\" is really\\n netos\\n\\n\\')
|
25
|
+
end
|
26
|
+
|
27
|
+
it 'backslash' do
|
28
|
+
Walters.escape_javascript(%(backslash\\test)).should == %(backslash\\\\test)
|
29
|
+
|
30
|
+
end
|
31
|
+
|
32
|
+
it 'closed html tags' do
|
33
|
+
Walters.escape_javascript(%(keep <open>, but dont </close> tags)).should == %(keep <open>, but dont <\\/close> tags)
|
34
|
+
end
|
35
|
+
|
36
|
+
it 'original returned if no escaping required' do
|
37
|
+
str = 'foobar'
|
38
|
+
Walters.escape_javascript(str).should equal str
|
39
|
+
end
|
40
|
+
|
41
|
+
it 'input must be utf8' do
|
42
|
+
lambda { Walters.escape_javascript('dont </close> tags'.encode('ISO-8859-1')) }.should raise_error(Encoding::CompatibilityError)
|
43
|
+
end
|
44
|
+
|
45
|
+
it 'return value has same encoding as input' do
|
46
|
+
str = "dont </close> tags"
|
47
|
+
Walters.escape_javascript(str).encoding.should == Encoding.find('UTF-8')
|
48
|
+
end
|
49
|
+
end
|
data/walters.gemspec
CHANGED
@@ -9,7 +9,7 @@ Gem::Specification.new do |s|
|
|
9
9
|
s.summary = 'JRuby wrapper for Houdini'
|
10
10
|
s.description = 'JRuby wrapper for Houdini html escaping library'
|
11
11
|
s.files = %w(walters.gemspec LICENSE README.md Rakefile)
|
12
|
-
s.files += Dir['lib/**/*.rb', 'ext/**/*.{c,cpp,h}', '{spec,libtest}/**/*.{c,cpp,h,rb}']
|
12
|
+
s.files += Dir['lib/**/*.rb', 'xni-ext/**/*.{c,cpp,h}', '{spec,libtest}/**/*.{c,cpp,h,rb}']
|
13
13
|
s.has_rdoc = false
|
14
14
|
s.license = 'Apache 2.0'
|
15
15
|
s.required_ruby_version = '>= 1.9.3'
|
@@ -17,5 +17,5 @@ Gem::Specification.new do |s|
|
|
17
17
|
s.add_dependency 'xni', '>= 0.1.0'
|
18
18
|
s.add_development_dependency 'rspec'
|
19
19
|
s.add_development_dependency 'rubygems-tasks'
|
20
|
-
s.extensions = ['ext/Rakefile']
|
20
|
+
s.extensions = ['xni-ext/Rakefile']
|
21
21
|
end
|
data/{ext → xni-ext}/Rakefile
RENAMED
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
data/{ext → xni-ext}/walters.cpp
RENAMED
@@ -1,3 +1,21 @@
|
|
1
|
+
/*
|
2
|
+
* Copyright (C) 2013 Wayne Meissner
|
3
|
+
*
|
4
|
+
* This file is part of the Walters project (http://github.com/wmeissner/walters).
|
5
|
+
*
|
6
|
+
* Licensed under the Apache License, Version 2.0 (the "License");
|
7
|
+
* you may not use this file except in compliance with the License.
|
8
|
+
* You may obtain a copy of the License at
|
9
|
+
*
|
10
|
+
* http://www.apache.org/licenses/LICENSE-2.0
|
11
|
+
*
|
12
|
+
* Unless required by applicable law or agreed to in writing, software
|
13
|
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
14
|
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
15
|
+
* See the License for the specific language governing permissions and
|
16
|
+
* limitations under the License.
|
17
|
+
*/
|
18
|
+
|
1
19
|
#include <stdlib.h>
|
2
20
|
#include <xni.h>
|
3
21
|
|
@@ -6,7 +24,7 @@ extern "C" {
|
|
6
24
|
#include "houdini/houdini.h"
|
7
25
|
}
|
8
26
|
|
9
|
-
#include "
|
27
|
+
#include "walters_xni.h"
|
10
28
|
|
11
29
|
XNI_EXPORT void
|
12
30
|
walters_free_cstring(RubyEnv *rb, void *cstr)
|
@@ -1,3 +1,21 @@
|
|
1
|
+
/*
|
2
|
+
* Copyright (C) 2013 Wayne Meissner
|
3
|
+
*
|
4
|
+
* This file is part of the Walters project (http://github.com/wmeissner/walters).
|
5
|
+
*
|
6
|
+
* Licensed under the Apache License, Version 2.0 (the "License");
|
7
|
+
* you may not use this file except in compliance with the License.
|
8
|
+
* You may obtain a copy of the License at
|
9
|
+
*
|
10
|
+
* http://www.apache.org/licenses/LICENSE-2.0
|
11
|
+
*
|
12
|
+
* Unless required by applicable law or agreed to in writing, software
|
13
|
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
14
|
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
15
|
+
* See the License for the specific language governing permissions and
|
16
|
+
* limitations under the License.
|
17
|
+
*/
|
18
|
+
|
1
19
|
#include <stdlib.h>
|
2
20
|
#include <xni.h>
|
3
21
|
|
@@ -6,7 +24,7 @@ extern "C" {
|
|
6
24
|
#include "houdini/houdini.h"
|
7
25
|
}
|
8
26
|
|
9
|
-
#include "
|
27
|
+
#include "walters_xni.h"
|
10
28
|
|
11
29
|
struct Walters_Buffer {
|
12
30
|
gh_buf gh;
|
@@ -1,5 +1,5 @@
|
|
1
|
-
#ifndef
|
2
|
-
#define
|
1
|
+
#ifndef WALTERS_XNI_H
|
2
|
+
#define WALTERS_XNI_H 1
|
3
3
|
|
4
4
|
#include <xni.h>
|
5
5
|
|
@@ -40,4 +40,4 @@ XNI_EXPORT void * walters__unescape_js(RubyEnv *, const char *, unsigned int);
|
|
40
40
|
XNI_EXPORT int xni_walters_load(RubyVM *,void **);
|
41
41
|
XNI_EXPORT void xni_walters_unload(RubyVM *, void *);
|
42
42
|
|
43
|
-
#endif /*
|
43
|
+
#endif /* WALTERS_XNI_H */
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: walters
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0
|
4
|
+
version: 0.1.0
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2013-
|
12
|
+
date: 2013-05-02 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: rake
|
@@ -79,7 +79,7 @@ description: JRuby wrapper for Houdini html escaping library
|
|
79
79
|
email: wmeissner@gmail.com
|
80
80
|
executables: []
|
81
81
|
extensions:
|
82
|
-
- ext/Rakefile
|
82
|
+
- xni-ext/Rakefile
|
83
83
|
extra_rdoc_files: []
|
84
84
|
files:
|
85
85
|
- walters.gemspec
|
@@ -89,23 +89,33 @@ files:
|
|
89
89
|
- lib/walters.rb
|
90
90
|
- lib/walters/version.rb
|
91
91
|
- lib/walters/walters.rb
|
92
|
-
-
|
93
|
-
-
|
94
|
-
-
|
95
|
-
-
|
96
|
-
-
|
97
|
-
-
|
98
|
-
-
|
99
|
-
- ext/houdini/
|
100
|
-
- ext/houdini/
|
101
|
-
- ext/
|
102
|
-
- ext/
|
103
|
-
- ext/
|
104
|
-
- ext/houdini/
|
105
|
-
- ext/houdini/
|
106
|
-
- ext/houdini/
|
107
|
-
- ext/
|
108
|
-
- ext/
|
92
|
+
- lib/walters/walters_xni.rb
|
93
|
+
- lib/walters/html/cgi.rb
|
94
|
+
- lib/walters/html/erb.rb
|
95
|
+
- lib/walters/html/haml.rb
|
96
|
+
- lib/walters/html/html_safety.rb
|
97
|
+
- lib/walters/html/rack.rb
|
98
|
+
- lib/walters/javascript/action_view.rb
|
99
|
+
- xni-ext/houdini/buffer.c
|
100
|
+
- xni-ext/houdini/houdini_href_e.c
|
101
|
+
- xni-ext/houdini/houdini_html_e.c
|
102
|
+
- xni-ext/houdini/houdini_html_u.c
|
103
|
+
- xni-ext/houdini/houdini_js_e.c
|
104
|
+
- xni-ext/houdini/houdini_js_u.c
|
105
|
+
- xni-ext/houdini/houdini_uri_e.c
|
106
|
+
- xni-ext/houdini/houdini_uri_u.c
|
107
|
+
- xni-ext/houdini/houdini_xml_e.c
|
108
|
+
- xni-ext/walters.cpp
|
109
|
+
- xni-ext/walters_buffer.cpp
|
110
|
+
- xni-ext/x86_64-darwin/__xni_walters_xni.cpp
|
111
|
+
- xni-ext/houdini/buffer.h
|
112
|
+
- xni-ext/houdini/houdini.h
|
113
|
+
- xni-ext/houdini/html_unescape.h
|
114
|
+
- xni-ext/x86_64-darwin/walters_xni.h
|
115
|
+
- spec/spec_helper.rb
|
116
|
+
- spec/walters/html_escape_spec.rb
|
117
|
+
- spec/walters/javascript_escape_spec.rb
|
118
|
+
- xni-ext/Rakefile
|
109
119
|
homepage: http://wiki.github.com/wmeissner/walters
|
110
120
|
licenses:
|
111
121
|
- Apache 2.0
|