Skip to content
Browse files

Make sure not to send any code as JSON

  • Loading branch information...
1 parent 478eaa4 commit bf2c2544a220baf10f672d81182e703255a10c7e @tnm committed Jul 15, 2012
Showing with 11 additions and 6 deletions.
  1. +9 −5 lib/pygments/mentos.py
  2. +2 −1 lib/pygments/popen.rb
View
14 lib/pygments/mentos.py
@@ -213,17 +213,21 @@ def start(self):
method = header["method"]
# 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", [])
kwargs = header.get("kwargs", {})
lexer = kwargs.get("lexer", None)
+ _bytes = 0
if lexer:
lexer = str(lexer)
- if method == 'highlight':
- text = args.encode('utf-8')
- else:
- text = None
+ # Read more bytes if necessary
+ _kwargs = header.get("kwargs", None)
+ if _kwargs:
+ _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.
try:
View
3 lib/pygments/popen.rb
@@ -151,7 +151,7 @@ def highlight(code, opts={})
opts[:options][:outencoding] ||= 'utf-8'
# 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
end
@@ -203,6 +203,7 @@ def mentos(method, args=[], kwargs={}, code=nil)
#
# If there's text/code to be highlighted, we send that after.
@in.write(out_header)
+ @in.write(code) if code
# Get the response header
header = @out.gets

0 comments on commit bf2c254

Please sign in to comment.
Something went wrong with that request. Please try again.