Open emrahtokalak opened 1 month ago
I tried to blame @gvkries but he said it was because of @lahma
Sounds like yet another STJ interop problem, I guess behavior could have changed after switch from Newtonsoft. Jint could also have some regression if no test coverage exists for this kind of thing.
This could be due to the way deserializeRequestData
handles the form data. I've tried to reproduce the error, but it works for me. Only difference, I used application/x-www-form-urlencoded
instead of multipart data.
This could be due to the way
deserializeRequestData
handles the form data. I've tried to reproduce the error, but it works for me. Only difference, I usedapplication/x-www-form-urlencoded
instead of multipart data.
Are you saying that in version 2.0.2, we can use the data returned from the deserializeRequestData method without any casting? I'm getting all kinds of errors in my tests. I think the problem is not with the deserializeRequestData method, but with the Json Serializer.
Not sure what has changed here in 2.0, but I think the issue is that deserializeRequestData
returns a dictionary with StringValues
in the values. That's why you get a System.InvalidOperationException: Cannot get the value of a token type 'StartArray' as a string
error. So I think you must cast to the correct type or handle this in another way.
Not sure what has changed here in 2.0, but I think the issue is that
deserializeRequestData
returns a dictionary withStringValues
in the values. That's why you get aSystem.InvalidOperationException: Cannot get the value of a token type 'StartArray' as a string
error. So I think you must cast to the correct type or handle this in another way.
Given that casting was not previously required in the script, I'm hesitant to state definitively that casting is now mandatory post-2.0. This could potentially result in a negative user experience.
I agree that this seems to be a regression.
To maintain compatibility with my existing scripts and minimize the need for casting, I've developed a custom method. This method implicitly converts non-string data types to strings to prevent runtime errors. However, explicit casting of non-string data types remains essential for correct data handling.
_formAsJsonObject = new GlobalMethod
{
Name = "requestFormAsJsonObject",
Method = serviceProvider => (Func<Dictionary<string, object>>)(() =>
{
var httpContextAccessor = serviceProvider.GetRequiredService<IHttpContextAccessor>();
var sanitizer = serviceProvider.GetRequiredService<IHtmlSanitizerService>();
var formData = httpContextAccessor.HttpContext.Request.Form;
var result = new Dictionary<string, object>();
foreach (var field in formData)
{
var sanitizedValues = field.Value.Select(value => sanitizer.Sanitize(value)).ToArray();
if (sanitizedValues.Length == 1)
{
result[field.Key] = sanitizedValues[0];
}
else
{
result[field.Key] = sanitizedValues;
}
}
return result;
})
};
The ideal usage should be as follows: I have come to the conclusion that we should cast it in every way.
var data = deserializeRequestData();
createContentItem("JintTestModel", true,
{
"JintTestModel": {
"Name": {
"Text": String(data.Name)
},
"Age": {
"Value": Number(data.Age)
},
"CreateDate": {
"Value": String(data.CreateDate)
}
},
"TitlePart": {
"Title": String(data.Title)
}
});
I think we should keep this opened.
I think we need a Jint type handler for StringValues which would return a string or a string[] based on the number of values.
We triaged this issue and set the milestone according to the priority we think is appropriate (see the docs on how we triage and prioritize issues).
This indicates when the core team may start working on it. However, if you'd like to contribute, we'd warmly welcome you to do that anytime. See our guide on contributions here.
Describe the bug
In versions 1.8.X, I was able to record content with my javascript code without any problems using the scriptManager.Evaluate method. In my tests on 2.0.2, I needed to cast the variables I read using the deserializeRequestData() method, it worked without the need for a previous cast operation. When I did not cast, I got a Json.Serialization error.
Orchard Core version 2.0.2
This used to work with 1.8.x, so it's a regression
To Reproduce
To simulate this error, I created a workflow and I am sending form-data to this workflow via postman, I am trying to read the values with the deserializeRequestData method in the script task and create new content.
Workflow-Jint-Test.zip
Expected behavior
I expect it to work with this js;
After the 2.x upgrade, it only works properly as I cast it below.
Is this an expected situation? Should I add cast functions to all my codes like this after the upgrade?