Skip to content

Commit

Permalink
parser: raise exception on bad startxref token
Browse files Browse the repository at this point in the history
  • Loading branch information
Guillaume Delugré committed Oct 1, 2017
1 parent 46c22b7 commit b105e24
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 22 deletions.
Binary file added lib/origami/.signature.rb.swp
Binary file not shown.
40 changes: 20 additions & 20 deletions lib/origami/parser.rb
Original file line number Diff line number Diff line change
Expand Up @@ -188,26 +188,6 @@ def target_data
@data.string.dup if @data
end

private

#
# Attempt to promote an object using the deferred casts.
#
def try_object_promotion(obj)
return obj unless Origami::OPTIONS[:enable_type_propagation] and @deferred_casts.key?(obj.reference)

types = @deferred_casts[obj.reference]
types = [ types ] unless types.is_a?(::Array)

# Promote object if a compatible type is found.
cast_type = types.find {|type| type < obj.class }
if cast_type
obj = obj.cast_to(cast_type, self)
else
obj
end
end

def error(msg = "") #:nodoc:
log(VERBOSE_QUIET, 'error', :red, msg.red)
end
Expand All @@ -228,6 +208,26 @@ def trace(msg = "") #:nodoc:
log(VERBOSE_TRACE, 'trace', :cyan, msg)
end

private

#
# Attempt to promote an object using the deferred casts.
#
def try_object_promotion(obj)
return obj unless Origami::OPTIONS[:enable_type_propagation] and @deferred_casts.key?(obj.reference)

types = @deferred_casts[obj.reference]
types = [ types ] unless types.is_a?(::Array)

# Promote object if a compatible type is found.
cast_type = types.find {|type| type < obj.class }
if cast_type
obj = obj.cast_to(cast_type, self)
else
obj
end
end

def log(level, prefix, color, message) #:nodoc:
return unless @options[:verbosity] >= level

Expand Down
4 changes: 2 additions & 2 deletions lib/origami/trailer.rb
Original file line number Diff line number Diff line change
Expand Up @@ -123,13 +123,13 @@ def self.parse(stream, parser = nil) #:nodoc:
end

if not stream.scan(@@regexp_xref)
#raise InvalidTrailerError, "Cannot get startxref value"
raise InvalidTrailerError, "Cannot get startxref value"
end

startxref = stream['startxref'].to_i

if not stream.scan(@@regexp_close)
#raise InvalidTrailerError, "No %%EOF token found"
parser.warn("No %%EOF token found") if parser
end

Trailer.new(startxref, dictionary)
Expand Down

0 comments on commit b105e24

Please sign in to comment.