fix: preserve float literal type in JSON config values#572
Open
18202781743 wants to merge 1 commit into
Open
Conversation
1. QJsonValue::toVariant() converts all JSON numbers to double internally, but when converting to QVariant, it degrades floating-point numbers without fractional parts (e.g., 1.0) to integers (qlonglong), losing the original float intent 2. Added JsonParseResult struct to keep raw JSON bytes alongside parsed document for float-literal detection 3. Added isOriginalValueFloat() helper that checks raw JSON text for '.' or 'e'/'E' characters in number literals 4. Added jsonValueToVariant() helper that converts QJsonValue to QVariant with forced double type when the raw literal was a float 5. Updated loadJsonFile() to return JsonParseResult with raw bytes 6. Applied float type preservation in both meta file loading and override loading paths 7. Updated unit test to verify that default values with float literals (like "1.0") remain as QMetaType::Double, and integer literals (like "1") remain as QMetaType::LongLong Log: Fixed issue where JSON config values with float literals (e.g., 1.0) were incorrectly degraded to integer types Influence: 1. Test config values with float literals (1.0, 2.5, 1e10) to ensure they remain double type 2. Test config values with integer literals (1, 100) to ensure they remain integer type 3. Verify override files with float values are correctly applied 4. Test backward compatibility with existing config files 5. Verify dde-dconfig set command accepts float values correctly 6. Test edge cases: negative floats, scientific notation, values without decimal part fix: 修复 JSON 配置值中浮点数字面量的类型保留问题 1. QJsonValue::toVariant() 将所有 JSON 数字转换为 double 类型,但 在转换为 QVariant 时,会将没有小数部分的浮点数(如 1.0)退化为整数 (qlonglong),丢失原始的浮点意图 2. 添加了 JsonParseResult 结构体,用于在解析文档时保留原始 JSON 字节数 据,以便进行浮点数字面量检测 3. 添加了 isOriginalValueFloat() 辅助函数,通过检查原始 JSON 文本中数字 字面量是否包含 '.' 或 'e'/'E' 字符来判断是否为浮点数 4. 添加了 jsonValueToVariant() 辅助函数,在将 QJsonValue 转换为 QVariant 时,如果原始字面量为浮点数则强制保留 double 类型 5. 更新了 loadJsonFile() 函数使其返回 JsonParseResult(包含原始字节 数据) 6. 在元文件加载和覆盖文件加载路径中都应用了浮点类型保留逻辑 7. 更新了单元测试,验证包含浮点字面量的默认值(如 "1.0")保持为 QMetaType::Double,整数字面量(如 "1")保持为 QMetaType::LongLong Log: 修复了 JSON 配置值中浮点数字面量(如 1.0)被错误退化为整数类型的 问题 Influence: 1. 测试包含浮点字面量的配置值(1.0, 2.5, 1e10)确保保持 double 类型 2. 测试包含整数字面量的配置值(1, 100)确保保持整数类型 3. 验证包含浮点值的覆盖文件是否正确应用 4. 测试与现有配置文件的向后兼容性 5. 验证 dde-dconfig set 命令是否正确接受浮点值 6. 测试边界情况:负浮点数、科学计数法、不包含小数部分的值
There was a problem hiding this comment.
Sorry @18202781743, you have reached your weekly rate limit of 500000 diff characters.
Please try again later or upgrade to continue using Sourcery
Contributor
|
[APPROVALNOTIFIER] This PR is NOT APPROVED This pull-request has been approved by: 18202781743 The full list of commands accepted by this bot can be found here. DetailsNeeds approval from an approver in each of these files:Approvers can indicate their approval by writing |
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.
internally, but when converting to QVariant, it degrades floating-point
numbers without fractional parts (e.g., 1.0) to integers (qlonglong),
losing the original float intent
document for float-literal detection
or 'e'/'E' characters in number literals
QVariant with forced double type when the raw literal was a float
override loading paths
(like "1.0") remain as QMetaType::Double, and integer literals (like
"1") remain as QMetaType::LongLong
Log: Fixed issue where JSON config values with float literals (e.g.,
1.0) were incorrectly degraded to integer types
Influence:
they remain double type
remain integer type
decimal part
fix: 修复 JSON 配置值中浮点数字面量的类型保留问题
在转换为 QVariant 时,会将没有小数部分的浮点数(如 1.0)退化为整数
(qlonglong),丢失原始的浮点意图
据,以便进行浮点数字面量检测
字面量是否包含 '.' 或 'e'/'E' 字符来判断是否为浮点数
时,如果原始字面量为浮点数则强制保留 double 类型
数据)
QMetaType::Double,整数字面量(如 "1")保持为 QMetaType::LongLong
Log: 修复了 JSON 配置值中浮点数字面量(如 1.0)被错误退化为整数类型的
问题
Influence: