mirror of
https://github.com/openvswitch/ovs
synced 2025-08-31 06:15:47 +00:00
json: Correct position tracking in JSON parser implementations.
When json_lex_input() returns false, the parser does not consume the byte passed in. That byte will get processed again in the next iteration of the json_parser_feed() loop. Therefore, until now, this code has double-counted bytes that cause a false return from json_lex_input(). This fixes the problem. Every input byte is now counted only once. Signed-off-by: Ben Pfaff <blp@nicira.com>
This commit is contained in:
@@ -1,4 +1,4 @@
|
||||
# Copyright (c) 2010, 2011 Nicira Networks
|
||||
# Copyright (c) 2010, 2011, 2012 Nicira Networks
|
||||
#
|
||||
# Licensed under the Apache License, Version 2.0 (the "License");
|
||||
# you may not use this file except in compliance with the License.
|
||||
@@ -420,13 +420,6 @@ class Parser(object):
|
||||
return True
|
||||
|
||||
def __lex_input(self, c):
|
||||
self.byte_number += 1
|
||||
if c == '\n':
|
||||
self.column_number = 0
|
||||
self.line_number += 1
|
||||
else:
|
||||
self.column_number += 1
|
||||
|
||||
eat = self.lex_state(self, c)
|
||||
assert eat is True or eat is False
|
||||
return eat
|
||||
@@ -557,7 +550,16 @@ class Parser(object):
|
||||
while True:
|
||||
if self.done or i >= len(s):
|
||||
return i
|
||||
if self.__lex_input(s[i]):
|
||||
|
||||
c = s[i]
|
||||
if self.__lex_input(c):
|
||||
self.byte_number += 1
|
||||
if c == '\n':
|
||||
self.column_number = 0
|
||||
self.line_number += 1
|
||||
else:
|
||||
self.column_number += 1
|
||||
|
||||
i += 1
|
||||
|
||||
def is_done(self):
|
||||
|
Reference in New Issue
Block a user