Repository navigation
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fix infinite loop
TestFail("[8 ", "$[0]");这个修复纠正了 peek() 在 EOF 时错误回退游标的行为。
peek()的正常逻辑是:调用SkipSpaceSafe()跳过空白、读取一个字符,再执行pos_ -= 1,让调用者后续还能消费这个字符。但对于
"[8",读完8后,pos_ == len_ == 2。旧版SkipSpaceSafe()此时没有前进,却返回了最后一个字符8;peek()又无条件把位置退回到1,于是数组解析反复读取同一个8:flowchart LR A["读完 8:pos = 2"] --> B["旧 peek:退回 pos = 1"] B --> C["再次跳过 8:pos = 2"] C --> B A --> D["修复后:保留 pos = 2,设置 EOF"] D --> E["错误检查终止解析"]新增的两个判断分别处理:
pos_ >= len_,直接设置kParseErrorEof并返回0,不再回退。"[8, ",扫描器返回最后一个空白字符,也应报告 EOF,不再退回这个空白。注意,返回
0本身不会结束while (peek() != ']'),因为0 != ']'。真正终止循环的是紧接着的RETURN_FALSE_IF_PARSE_ERROR(...):它检测到已经设置的 EOF 错误后返回false。最终结果是
"8"和kParseErrorEof:保留已经提取的值,同时明确报告数组缺少闭合]。