-
Notifications
You must be signed in to change notification settings - Fork 7
Encode form name #7515
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: develop
Are you sure you want to change the base?
Encode form name #7515
Changes from all commits
d56b062
7cb411f
9946543
21bd355
1a45338
e4a743a
734ece4
51db816
d969731
7d1a56b
b56f038
bc925a0
f8cae4f
0653561
2a3e7b4
6ed42aa
d36f745
c7b22c3
4205ffa
3d41479
2d78208
9127b05
2a19108
dd4897e
73a282f
1e81641
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -76,6 +76,7 @@ | |
| import java.util.Collection; | ||
| import java.util.Collections; | ||
| import java.util.HashMap; | ||
| import java.util.LinkedHashMap; | ||
| import java.util.List; | ||
| import java.util.Map; | ||
| import java.util.function.Predicate; | ||
|
|
@@ -185,51 +186,26 @@ public static PropertyValues getPropertyValuesForFormBinding(PropertyValues pvs, | |
| return ret; | ||
| } | ||
|
|
||
| static final String FORM_DATE_ENCODED_PARAM = "formDataEncoded"; | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Seems like we need more client-side updates as
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I was hoping encodeFormDataQuote() would cover the client-side code change. |
||
|
|
||
| /** | ||
| * When a double quote is encountered in a multipart/form-data context, it is encoded as %22 using URL-encoding by browsers. | ||
| * This process replaces the double quote with its hexadecimal equivalent in a URL-safe format, preventing it from being misinterpreted as the end of a value or a boundary. | ||
| * The consequence of such encoding is we can't distinguish '"' from the actual '%22' in parameter name. | ||
| * As a workaround, a client-side util `encodeFormDataQuote` is used to convert %22 to %2522 and " to %22 explicitly, while passing in an additional param formDataEncoded=true. | ||
| * This class converts those encoded param names back to its decoded form during PropertyValues binding. | ||
| * See Issue 52827, 52925 and 52119 for more information. | ||
| */ | ||
| /// Some characters can be mishandled by the browser in multipart/formdata requests (e.g. doublequote and backslask). | ||
| /// We support an encoding from fields to avoid these characters, see {@link PageFlowUtil#encodeFormName} and {@link PageFlowUtil#decodeFormName}. | ||
| static public class ViewActionParameterPropertyValues extends ServletRequestParameterPropertyValues | ||
| { | ||
|
|
||
| public ViewActionParameterPropertyValues(ServletRequest request) { | ||
| this(request, null, null); | ||
| } | ||
|
|
||
| public ViewActionParameterPropertyValues(ServletRequest request, @Nullable String prefix, @Nullable String prefixSeparator) | ||
| { | ||
| super(request, prefix, prefixSeparator); | ||
| if (isFormDataEncoded()) | ||
| { | ||
| for (int i = 0; i < getPropertyValues().length; i++) | ||
| { | ||
| PropertyValue formDataPropValue = getPropertyValues()[i]; | ||
| String propValueName = formDataPropValue.getName(); | ||
| String decoded = PageFlowUtil.decodeQuoteEncodedFormDataKey(propValueName); | ||
| if (!propValueName.equals(decoded)) | ||
| setPropertyValueAt(new PropertyValue(decoded, formDataPropValue.getValue()), i); | ||
| } | ||
| } | ||
| } | ||
|
|
||
| private boolean isFormDataEncoded() | ||
| { | ||
| PropertyValue formDataPropValue = getPropertyValue(FORM_DATE_ENCODED_PARAM); | ||
| if (formDataPropValue != null) | ||
| for (int i = 0; i < getPropertyValues().length; i++) | ||
| { | ||
| Object v = formDataPropValue.getValue(); | ||
| String formDataPropValueStr = v == null ? null : String.valueOf(v); | ||
| if (StringUtils.isNotBlank(formDataPropValueStr)) | ||
| return (Boolean) ConvertUtils.convert(formDataPropValueStr, Boolean.class); | ||
| PropertyValue formDataPropValue = getPropertyValues()[i]; | ||
| String propValueName = formDataPropValue.getName(); | ||
| String decoded = PageFlowUtil.decodeFormName(propValueName); | ||
| if (!propValueName.equals(decoded)) | ||
| setPropertyValueAt(new PropertyValue(decoded, formDataPropValue.getValue()), i); | ||
| } | ||
|
|
||
| return false; | ||
| } | ||
| } | ||
|
|
||
|
|
@@ -725,9 +701,7 @@ public <T> T convertIfNecessary(Object value, Class<T> requiredType, MethodParam | |
| */ | ||
| protected Map<String, MultipartFile> getFileMap() | ||
| { | ||
| if (getViewContext().getRequest() instanceof MultipartHttpServletRequest) | ||
| return ((MultipartHttpServletRequest)getViewContext().getRequest()).getFileMap(); | ||
| return Collections.emptyMap(); | ||
| return PageFlowUtil.getFileMap(getViewContext().getRequest()); | ||
| } | ||
|
|
||
| protected List<AttachmentFile> getAttachmentFileList() | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.