summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorKornelius Kalnbach <murphy@rubychan.de>2013-07-21 16:44:00 +0200
committerKornelius Kalnbach <murphy@rubychan.de>2013-07-21 16:44:00 +0200
commitb266cb62e4fc08b31dfa1b9a2700e5d555d13afb (patch)
tree8e88175ab9bf9d63eb504ce666b0e0aca0c0f895
parent5c23a731ca55729fc65630eca3b37a5b1a71e5b1 (diff)
parentea107396fdd72cdbbaf4820d09a87bd879ba7e6c (diff)
downloadcoderay-b266cb62e4fc08b31dfa1b9a2700e5d555d13afb.tar.gz
Merge branch 'master' into fix-cache-attack
-rw-r--r--lib/coderay/encoders/debug_lint.rb3
-rw-r--r--lib/coderay/encoders/lint.rb4
-rwxr-xr-xlib/coderay/token_kinds.rb5
-rwxr-xr-xtest/functional/basic.rb4
4 files changed, 7 insertions, 9 deletions
diff --git a/lib/coderay/encoders/debug_lint.rb b/lib/coderay/encoders/debug_lint.rb
index 2c14186..a4eba2c 100644
--- a/lib/coderay/encoders/debug_lint.rb
+++ b/lib/coderay/encoders/debug_lint.rb
@@ -18,7 +18,8 @@ module Encoders
register_for :debug_lint
def text_token text, kind
- raise Lint::EmptyToken, 'empty token' if text.empty?
+ raise Lint::EmptyToken, 'empty token for %p' % [kind] if text.empty?
+ raise Lint::UnknownTokenKind, 'unknown token kind %p (text was %p)' % [kind, text] unless TokenKinds.has_key? kind
super
end
diff --git a/lib/coderay/encoders/lint.rb b/lib/coderay/encoders/lint.rb
index 4601e90..88c8bd1 100644
--- a/lib/coderay/encoders/lint.rb
+++ b/lib/coderay/encoders/lint.rb
@@ -17,10 +17,12 @@ module Encoders
InvalidTokenStream = Class.new StandardError
EmptyToken = Class.new InvalidTokenStream
+ UnknownTokenKind = Class.new InvalidTokenStream
IncorrectTokenGroupNesting = Class.new InvalidTokenStream
def text_token text, kind
- raise EmptyToken, 'empty token' if text.empty?
+ raise EmptyToken, 'empty token for %p' % [kind] if text.empty?
+ raise UnknownTokenKind, 'unknown token kind %p (text was %p)' % [kind, text] unless TokenKinds.has_key? kind
end
def begin_group kind
diff --git a/lib/coderay/token_kinds.rb b/lib/coderay/token_kinds.rb
index 9137a49..5f49d77 100755
--- a/lib/coderay/token_kinds.rb
+++ b/lib/coderay/token_kinds.rb
@@ -1,10 +1,7 @@
module CodeRay
# A Hash of all known token kinds and their associated CSS classes.
- TokenKinds = Hash.new do |h, k|
- warn 'Undefined Token kind: %p' % [k] if $CODERAY_DEBUG
- false
- end
+ TokenKinds = Hash.new(false)
# speedup
TokenKinds.compare_by_identity if TokenKinds.respond_to? :compare_by_identity
diff --git a/test/functional/basic.rb b/test/functional/basic.rb
index 3053b54..752d4ba 100755
--- a/test/functional/basic.rb
+++ b/test/functional/basic.rb
@@ -164,9 +164,7 @@ more code # and another comment, in-line.
end
end
assert_equal 'reserved', CodeRay::TokenKinds[:reserved]
- assert_warning 'Undefined Token kind: :shibboleet' do
- assert_equal false, CodeRay::TokenKinds[:shibboleet]
- end
+ assert_equal false, CodeRay::TokenKinds[:shibboleet]
end
class Milk < CodeRay::Encoders::Encoder