Skip to content

Commit

Permalink
Make sure not to send any code as JSON
Browse files Browse the repository at this point in the history
  • Loading branch information
tnm committed Jul 16, 2012
1 parent 478eaa4 commit bf2c254
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 6 deletions.
14 changes: 9 additions & 5 deletions lib/pygments/mentos.py
Expand Up @@ -213,17 +213,21 @@ def start(self):
method = header["method"] method = header["method"]


# Default to empty array and empty dictionary if nothing is given. Default to # Default to empty array and empty dictionary if nothing is given. Default to
# no text and no further bytes to read. # no further bytes to read.
args = header.get("args", []) args = header.get("args", [])
kwargs = header.get("kwargs", {}) kwargs = header.get("kwargs", {})
lexer = kwargs.get("lexer", None) lexer = kwargs.get("lexer", None)
_bytes = 0
if lexer: if lexer:
lexer = str(lexer) lexer = str(lexer)


if method == 'highlight': # Read more bytes if necessary
text = args.encode('utf-8') _kwargs = header.get("kwargs", None)
else: if _kwargs:
text = None _bytes = _kwargs.get("bytes", 0)

# Read up to the given number bytes (possibly 0)
text = sys.stdin.read(_bytes)


# And now get the actual data from pygments. # And now get the actual data from pygments.
try: try:
Expand Down
3 changes: 2 additions & 1 deletion lib/pygments/popen.rb
Expand Up @@ -151,7 +151,7 @@ def highlight(code, opts={})
opts[:options][:outencoding] ||= 'utf-8' opts[:options][:outencoding] ||= 'utf-8'


# Get back the string from mentos and force encoding if we can # Get back the string from mentos and force encoding if we can
str = mentos(:highlight, code, opts, code) str = mentos(:highlight, nil, opts, code)
str.force_encoding(opts[:options][:outencoding]) if str.respond_to?(:force_encoding) str.force_encoding(opts[:options][:outencoding]) if str.respond_to?(:force_encoding)
str str
end end
Expand Down Expand Up @@ -203,6 +203,7 @@ def mentos(method, args=[], kwargs={}, code=nil)
# #
# If there's text/code to be highlighted, we send that after. # If there's text/code to be highlighted, we send that after.
@in.write(out_header) @in.write(out_header)
@in.write(code) if code


# Get the response header # Get the response header
header = @out.gets header = @out.gets
Expand Down

0 comments on commit bf2c254

Please sign in to comment.