Skip to content
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

timob-7850: Convert fileType Number input to integer before processing it #1610

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -1001,7 +1001,12 @@ public void send(Object userData) throws MethodNotSupportedException
boolean queryStringAltered = false;
for (String key : data.keySet()) {
Object value = data.get(key);

//fileType can only accept an int, or a string representation of an int.
//so if users input a number for fileType, we need to convert it to int before processing.
if (key.equals("fileType") && (value instanceof Number)) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What if the value is a string like the comment mentions?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

its fine if its a string, since this int will be converted to string anyways. The problem that caused this was when the user enter "fileType: 2". We recognized that "2" as a Double, so when we convert it to String, it becomes 2.0, which is an invalid fileType. So a String that is "2.0" would NOT work.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This fix is to mainly address the issue when user types an int in JS, like "2", for fileType, we recognize that as a Double, while he/she thinks that this will be an integer.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why are we even checking for fileType here? fileType isn't a standard property, it is specific to the bug in the test case

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmm, you're right. I thought it was but this is user input, which means it should've worked in the first place. I just tested it on my phone and the original test case works... It wasn't working before. Something weird is going on. I'll investigate further on Sunday. Thanks for pointing this out.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The point is, the change in place does not handle:
: "123"

because the value passed to the send() method on the java side see the value as java.lang.String and thus will never pass a instanceof check.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@hieupham007 when you investigate, if you can reproduce failure against master can you please attach the logcat output to the Jira ticket for reference?

Number tempValue = (Number) value;
value = tempValue.intValue();
}
if (isPostOrPut && (value != null)) {
// if the value is a proxy, we need to get the actual file object
if (value instanceof TiFileProxy) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ public static TiBlob blobFromImage(Bitmap image)
data = bos.toByteArray();
}

TiBlob blob = new TiBlob(TYPE_IMAGE, data, "image/bitmap");
TiBlob blob = new TiBlob(TYPE_IMAGE, data, "image/png");
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How can we assume that image/png is the right mimeType? There are several different image types, PNG is only one

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It seems that we're trying to convert this to png. But it could be in a different format if it can't be converted. I'll fix this. Thanks

blob.width = image.getWidth();
blob.height = image.getHeight();
return blob;
Expand Down