gr_string_escape 0.3.1
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/.document +5 -0
- data/.gitignore +22 -0
- data/LICENSE +20 -0
- data/README.rdoc +17 -0
- data/Rakefile +61 -0
- data/VERSION +1 -0
- data/ext/gr_string_escape/extconf.rb +4 -0
- data/ext/gr_string_escape/gr_string_escape.c +1162 -0
- data/gr_string_escape.gemspec +55 -0
- data/test/helper.rb +12 -0
- data/test/new_assertions.rb +21 -0
- data/test/test_gr_string_escape.rb +114 -0
- metadata +82 -0
@@ -0,0 +1,55 @@
|
|
1
|
+
# Generated by jeweler
|
2
|
+
# DO NOT EDIT THIS FILE DIRECTLY
|
3
|
+
# Instead, edit Jeweler::Tasks in Rakefile, and run the gemspec command
|
4
|
+
# -*- encoding: utf-8 -*-
|
5
|
+
|
6
|
+
Gem::Specification.new do |s|
|
7
|
+
s.name = %q{gr_string_escape}
|
8
|
+
s.version = "0.3.1"
|
9
|
+
|
10
|
+
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
11
|
+
s.authors = ["Michael Economy", "Curtis Schofield"]
|
12
|
+
s.date = %q{2010-10-22}
|
13
|
+
s.description = %q{Code for Goodreads String Parsing}
|
14
|
+
s.email = %q{github.com@robotarmyma.de}
|
15
|
+
s.extensions = ["ext/gr_string_escape/extconf.rb"]
|
16
|
+
s.extra_rdoc_files = [
|
17
|
+
"LICENSE",
|
18
|
+
"README.rdoc"
|
19
|
+
]
|
20
|
+
s.files = [
|
21
|
+
".document",
|
22
|
+
".gitignore",
|
23
|
+
"LICENSE",
|
24
|
+
"README.rdoc",
|
25
|
+
"Rakefile",
|
26
|
+
"VERSION",
|
27
|
+
"ext/gr_string_escape/extconf.rb",
|
28
|
+
"ext/gr_string_escape/gr_string_escape.c",
|
29
|
+
"gr_string_escape.gemspec",
|
30
|
+
"test/helper.rb",
|
31
|
+
"test/new_assertions.rb",
|
32
|
+
"test/test_gr_string_escape.rb"
|
33
|
+
]
|
34
|
+
s.homepage = %q{http://github.com/robotarmy/gr_string_escape}
|
35
|
+
s.rdoc_options = ["--charset=UTF-8"]
|
36
|
+
s.require_paths = ["lib"]
|
37
|
+
s.rubygems_version = %q{1.3.7}
|
38
|
+
s.summary = %q{Goodreads string parser}
|
39
|
+
s.test_files = [
|
40
|
+
"test/helper.rb",
|
41
|
+
"test/new_assertions.rb",
|
42
|
+
"test/test_gr_string_escape.rb"
|
43
|
+
]
|
44
|
+
|
45
|
+
if s.respond_to? :specification_version then
|
46
|
+
current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
|
47
|
+
s.specification_version = 3
|
48
|
+
|
49
|
+
if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
|
50
|
+
else
|
51
|
+
end
|
52
|
+
else
|
53
|
+
end
|
54
|
+
end
|
55
|
+
|
data/test/helper.rb
ADDED
@@ -0,0 +1,12 @@
|
|
1
|
+
require 'rubygems'
|
2
|
+
require 'test/unit'
|
3
|
+
|
4
|
+
$LOAD_PATH.unshift(File.dirname(__FILE__))
|
5
|
+
$LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
|
6
|
+
require 'gr_string_escape'
|
7
|
+
require 'new_assertions'
|
8
|
+
class Test::Unit::TestCase
|
9
|
+
include NewAssertions
|
10
|
+
end
|
11
|
+
|
12
|
+
|
@@ -0,0 +1,21 @@
|
|
1
|
+
module NewAssertions
|
2
|
+
def assert_redirects
|
3
|
+
assert_response(:redirect)
|
4
|
+
end
|
5
|
+
def assert_blank(object)
|
6
|
+
assert object.blank?, "#{object.inspect} is not blank"
|
7
|
+
end
|
8
|
+
def assert_size(size,object)
|
9
|
+
assert_equal size, object.size,
|
10
|
+
"#{object.inspect} was expected to be size #{size} " +
|
11
|
+
"but was size #{object.size}"
|
12
|
+
end
|
13
|
+
|
14
|
+
def assert_body_contains(string)
|
15
|
+
assert_match string, response.body
|
16
|
+
end
|
17
|
+
|
18
|
+
def assert_scope_equal(expected_hash,scope)
|
19
|
+
assert_equal expected_hash,scope.scope(:find)
|
20
|
+
end
|
21
|
+
end
|
@@ -0,0 +1,114 @@
|
|
1
|
+
#encoding: utf-8
|
2
|
+
require 'helper'
|
3
|
+
|
4
|
+
class TestGrStringEscape < Test::Unit::TestCase
|
5
|
+
|
6
|
+
STRING_ESCAPE = GrStringEscape.new
|
7
|
+
|
8
|
+
def escape_text(text, cap_at = 0, add_dots = false)
|
9
|
+
STRING_ESCAPE.parse(text.to_s, cap_at, add_dots ? '...' : '')
|
10
|
+
end
|
11
|
+
|
12
|
+
def test_gr_string_escape_default
|
13
|
+
str = "[hi:philip]"
|
14
|
+
assert_equal str, GrStringEscape.new.parse('[hi:philip]',str.size,"")
|
15
|
+
end
|
16
|
+
|
17
|
+
|
18
|
+
|
19
|
+
|
20
|
+
def test_cap_at
|
21
|
+
test_texts = ["check for <i>italic multi-line\nblah blah</i> now normal"]
|
22
|
+
for text in test_texts
|
23
|
+
escape_text(text, text.length / 2, false)
|
24
|
+
end
|
25
|
+
end
|
26
|
+
|
27
|
+
def test_unicode
|
28
|
+
input = "日本語"
|
29
|
+
result = escape_text(input, 1)
|
30
|
+
assert_size 3, result
|
31
|
+
|
32
|
+
input = "ひらがな"
|
33
|
+
result = escape_text(input)
|
34
|
+
assert_size input.size, result
|
35
|
+
|
36
|
+
|
37
|
+
result = escape_text(input, 2)
|
38
|
+
assert_size 6,result
|
39
|
+
end
|
40
|
+
|
41
|
+
def test_escaping_javascript
|
42
|
+
assert(!escape_text("<script> javascript</script>").include?("<"))
|
43
|
+
assert(!escape_text("< script>").include?("<"))
|
44
|
+
assert(!escape_text("<script var='some other nonsense'>").include?("<"))
|
45
|
+
assert(!escape_text('<a href="javascript:blah">testing</a>').include?("<"))
|
46
|
+
onclick_test = escape_text('<a href="http://www.goodreads.com/test" onclick="bad">testing</a>')
|
47
|
+
assert(!onclick_test.include?("<") || !onclick_test.include?("onclick"))
|
48
|
+
end
|
49
|
+
|
50
|
+
def test_escape_all_tags
|
51
|
+
assert_equal("<u><strong>T</strong></u>", escape_text("<u><b>T</u></b>"))
|
52
|
+
end
|
53
|
+
|
54
|
+
def test_escaping_styles_and_classes
|
55
|
+
assert(escape_text("<p>javascript</p>").include?("<"))
|
56
|
+
end
|
57
|
+
|
58
|
+
def test_url_highlighting
|
59
|
+
assert(escape_text("http://www.goodreads.com/").include?("<a "))
|
60
|
+
end
|
61
|
+
|
62
|
+
def test_url_highlighting
|
63
|
+
assert(escape_text("<b> http://www.goodreads.com/").include?("<a "))
|
64
|
+
end
|
65
|
+
|
66
|
+
def test_url_highlighting_advanced
|
67
|
+
assert(escape_text("<p>javascript</p> http://www.goodreads.com/").include?("<a "))
|
68
|
+
end
|
69
|
+
|
70
|
+
def test_url_highlighting_advanced2
|
71
|
+
assert(escape_text("[book:harrypotter|1]<p>javascript</p> <i> http://www.goodreads.com/").include?('href="http://www.goodreads.com/"'))
|
72
|
+
end
|
73
|
+
|
74
|
+
def test_escaping_divs
|
75
|
+
assert(!escape_text("<div>javascript</div>").include?("<"))
|
76
|
+
end
|
77
|
+
|
78
|
+
def test_escaping_styles_and_classes2
|
79
|
+
assert(!escape_text("<style>").include?("<"))
|
80
|
+
end
|
81
|
+
|
82
|
+
def test_escaping_styles_and_classes3
|
83
|
+
assert(!escape_text('<p style="font-weight:bold"').include?("<"))
|
84
|
+
end
|
85
|
+
|
86
|
+
def test_escaping_styles_and_classes4
|
87
|
+
escaped = escape_text('<a class="blah" href="javascript:blah">testing</a>')
|
88
|
+
assert(!escaped.include?("class") || !escaped.include?("<"))
|
89
|
+
end
|
90
|
+
|
91
|
+
|
92
|
+
def test_escaping_nesting
|
93
|
+
assert_equal("<p><em>TEST</em></p>", escape_text("<p><i>TEST</i></p>"))
|
94
|
+
end
|
95
|
+
|
96
|
+
|
97
|
+
def test_escaping_nesting2
|
98
|
+
assert_equal("<em><em>TEST</em></em>", escape_text("<i><i>TEST</i></i>"))
|
99
|
+
end
|
100
|
+
|
101
|
+
def test_empty_url
|
102
|
+
escape_text("<img src= / >blah")
|
103
|
+
end
|
104
|
+
|
105
|
+
def test_escaping_nesting3
|
106
|
+
assert_equal("<em><em>TEST</em>blah <strong>test2</strong></em>",
|
107
|
+
escape_text("<i><i>TEST</i>blah <b>test2</b></i>"))
|
108
|
+
end
|
109
|
+
|
110
|
+
|
111
|
+
def test_escape_all_tags
|
112
|
+
assert_equal("<u><strong>T</strong></u>", escape_text("<u><b>T</u></b>"))
|
113
|
+
end
|
114
|
+
end
|
metadata
ADDED
@@ -0,0 +1,82 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: gr_string_escape
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
hash: 17
|
5
|
+
prerelease: false
|
6
|
+
segments:
|
7
|
+
- 0
|
8
|
+
- 3
|
9
|
+
- 1
|
10
|
+
version: 0.3.1
|
11
|
+
platform: ruby
|
12
|
+
authors:
|
13
|
+
- Michael Economy
|
14
|
+
- Curtis Schofield
|
15
|
+
autorequire:
|
16
|
+
bindir: bin
|
17
|
+
cert_chain: []
|
18
|
+
|
19
|
+
date: 2010-10-22 00:00:00 -07:00
|
20
|
+
default_executable:
|
21
|
+
dependencies: []
|
22
|
+
|
23
|
+
description: Code for Goodreads String Parsing
|
24
|
+
email: github.com@robotarmyma.de
|
25
|
+
executables: []
|
26
|
+
|
27
|
+
extensions:
|
28
|
+
- ext/gr_string_escape/extconf.rb
|
29
|
+
extra_rdoc_files:
|
30
|
+
- LICENSE
|
31
|
+
- README.rdoc
|
32
|
+
files:
|
33
|
+
- .document
|
34
|
+
- .gitignore
|
35
|
+
- LICENSE
|
36
|
+
- README.rdoc
|
37
|
+
- Rakefile
|
38
|
+
- VERSION
|
39
|
+
- ext/gr_string_escape/extconf.rb
|
40
|
+
- ext/gr_string_escape/gr_string_escape.c
|
41
|
+
- gr_string_escape.gemspec
|
42
|
+
- test/helper.rb
|
43
|
+
- test/new_assertions.rb
|
44
|
+
- test/test_gr_string_escape.rb
|
45
|
+
has_rdoc: true
|
46
|
+
homepage: http://github.com/robotarmy/gr_string_escape
|
47
|
+
licenses: []
|
48
|
+
|
49
|
+
post_install_message:
|
50
|
+
rdoc_options:
|
51
|
+
- --charset=UTF-8
|
52
|
+
require_paths:
|
53
|
+
- lib
|
54
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
55
|
+
none: false
|
56
|
+
requirements:
|
57
|
+
- - ">="
|
58
|
+
- !ruby/object:Gem::Version
|
59
|
+
hash: 3
|
60
|
+
segments:
|
61
|
+
- 0
|
62
|
+
version: "0"
|
63
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
64
|
+
none: false
|
65
|
+
requirements:
|
66
|
+
- - ">="
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
hash: 3
|
69
|
+
segments:
|
70
|
+
- 0
|
71
|
+
version: "0"
|
72
|
+
requirements: []
|
73
|
+
|
74
|
+
rubyforge_project:
|
75
|
+
rubygems_version: 1.3.7
|
76
|
+
signing_key:
|
77
|
+
specification_version: 3
|
78
|
+
summary: Goodreads string parser
|
79
|
+
test_files:
|
80
|
+
- test/helper.rb
|
81
|
+
- test/new_assertions.rb
|
82
|
+
- test/test_gr_string_escape.rb
|