Repository navigation
fix: honor AutoTypeBeforeHandler for JSON.parse(byte[]) array elements (issue #7952) - #7962
Open
divine-punishment wants to merge 1 commit into
Open
divine-punishment wants to merge 1 commit into
divine-punishment wants to merge 1 commit into
Conversation
With Feature.ErrorOnNotSupportAutoType enabled and an AutoTypeBeforeHandler that authorizes the requested type, JSON.parse(String) and JSON.parse(byte[]) behaved inconsistently for a top-level array containing @type objects: the String path succeeded while the byte[] path threw 'autoType not support', even though the same handler would allow the type (issue alibaba#7952). JSONReader.readArray delegated nested objects to the handler-aware ObjectReaderImplObject only when a context-level handler was set, ignoring a provider-level handler (ObjectReaderProvider#setAutoTypeBeforeHandler). The byte[] entry path therefore fell into the plain readObject, which rejects @type outright under ErrorOnNotSupportAutoType. - Check the provider-level handler in readArray's nested-object guard, so authorized types resolve exactly as on the String path - Reorder the guard so isReference() is checked first: reference objects as array elements must keep taking the reference path regardless of any handler, otherwise {$ref} values are parsed as literal maps (guarded by the existing Issue2140 regression test) Unauthorized types are still rejected under ErrorOnNotSupportAutoType on both paths.
This branch has not been deployed
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.
What this PR does / why we need it?
Fixes #7952.
With
Feature.ErrorOnNotSupportAutoTypeenabled and anAutoTypeBeforeHandlerthat authorizes the requested type,JSON.parse(String)andJSON.parse(byte[])behaved inconsistently for a top-level array containing@typeobjects: the String path succeeded while the byte[] path threwautoType not support, even though the same handler would allow the type.Root cause:
JSONReader.readArraydelegated nested objects to the handler-awareObjectReaderImplObjectonly when a context-level handler was set, ignoring a provider-level handler (ObjectReaderProvider#setAutoTypeBeforeHandler). The byte[] entry path therefore fell into the plainreadObject, which rejects@typeoutright underErrorOnNotSupportAutoType.Summary of your change
JSONReader.readArray: also check the provider-level handler in the nested-object guard, so authorized types resolve exactly as on the String pathisReference()is checked first: reference objects as array elements must keep taking the reference path regardless of any handler, otherwise$refvalues would be parsed as literal maps (covered by the existingIssue2140regression test)Unauthorized types are still rejected under
ErrorOnNotSupportAutoTypeon both paths.Please indicate you've done the following:
中文说明
修复内容
Fixes #7952:开启
ErrorOnNotSupportAutoType且AutoTypeBeforeHandler已授权目标类型时,顶层带@type的数组:JSON.parse(String)成功,JSON.parse(byte[])抛autoType not support。根因:
JSONReader.readArray只有在 context 级 handler 存在时才把嵌套对象委托给支持 handler 的ObjectReaderImplObject,provider 级 handler(ObjectReaderProvider#setAutoTypeBeforeHandler)被忽略,byte[] 路径落入无条件拒绝@type的通用readObject。修改方式
readArray的守卫补充 provider 级 handler 检查,授权类型与 String 路径一致地解析isReference()检查前置:$ref引用元素必须始终走引用路径,否则会被解析成字面量 map(现有Issue2140回归测试覆盖此场景)未授权类型在两条路径上仍然被
ErrorOnNotSupportAutoType拒绝。