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

IPTCParser now takes the raw bytes of an IPTCRecord element into account #4

Open
wants to merge 2 commits into
base: trunk
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -438,10 +438,20 @@ public int compare(final IptcRecord e1, final IptcRecord e2) {
}
bos.write(element.iptcType.getType());

final byte[] recordData = element.value.getBytes("ISO-8859-1");
if (!new String(recordData, "ISO-8859-1").equals(element.value)) {
throw new ImageWriteException(
"Invalid record value, not ISO-8859-1");
/**
* favor raw bytes over value. This allows callers to use their
* own encoding of fields.
*/
final byte[] recordData;
if( element.getRawBytes() != null && element.getRawBytes().length > 0 ) {
Copy link
Member

Choose a reason for hiding this comment

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

Ah, I had a better look using the git history, and getRawBytes returned the bytes returned from a getBytes("ISO-8859-1") call.

image

So the only way that getRawBytes would return null, would be if there was an error encoding the String into ISO-8859-1. Which would also happen in the other branch of the if statement here.

So I believe the change wouldn't help you, as we would be still using ISO-8859-1 before you got the bytes.

recordData = element.getRawBytes();
}
else {
recordData = element.value.getBytes("ISO-8859-1");
if (!new String(recordData, "ISO-8859-1").equals(element.value)) {
throw new ImageWriteException(
"Invalid record value, not ISO-8859-1");
}
}

bos.write2Bytes(recordData.length);
Expand Down