-
Notifications
You must be signed in to change notification settings - Fork 10.5k
feat: fix form calculation fields, related to #20214 #20223
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
feat: fix form calculation fields, related to #20214 #20223
Conversation
src/core/annotation.js
Outdated
decodedValue = decodedValue[0]; | ||
} | ||
|
||
class WidgetAnnotation extends Annotation { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why is this class repeated inside the class with the exact same name and same of the exact same code? Does that actually work?
yarn.lock
Outdated
@@ -0,0 +1,6507 @@ | |||
# THIS IS AN AUTOGENERATED FILE. DO NOT EDIT THIS FILE DIRECTLY. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This file needs to be removed; it's unrelated to the patch.
src/core/annotation.js
Outdated
data.fieldValue = decodedValue; | ||
} | ||
/** | ||
* Fix calculation values that show repeating patterns due to JavaScript execution errors |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This feels a bit arbitrary to me. How do we know for sure that the repeated value wasn't intended by the user? Is there anything in the PDF specification that explains how to deal with this situation?
Please make sure the commits are squashed into one, and ensure that that commit has a good commit message that explains the issue and the approach for fixing it in a concise manner. |
Fixes :
This PR fixes issue #20214 where PDF form calculation fields display repeating digit patterns (e.g., "37037037" instead of "3" or "37.037.03" instead of "3") when calculated values are processed incorrectly by the PDF.js JavaScript engine.
Problem :
When users fill out PDF forms with calculated fields (like mean scores), the calculation results sometimes show malformed repeating patterns:
"37037037" instead of "37"
"37.037.03" instead of "3"
"333333" instead of "3"
This occurs when PDF calculation scripts run incorrectly in PDF.js JavaScript environment, causing string concatenation instead of proper numeric calculation.
Root Cause :
The issue stems from:
Solution :
Enhanced the WidgetAnnotation constructor's value processing logic
Added _fixRepeatingCalculationValue() method to detect and correct malformed calculation results
Implemented pattern detection for various types of calculation errors
Added comprehensive logging for debugging
Maintains full backward compatibility
Files Changed :