mirror of
https://github.com/zxing/zxing.git
synced 2025-03-05 20:48:51 -08:00
Prevent encoding of the empty string for PDF417 (#1523)
* Added code so that the PDF417 encoder throws an exception when attempting to encode the empty string
This commit is contained in:
parent
c7a7b30f04
commit
78faea8058
|
@ -171,6 +171,10 @@ final class PDF417HighLevelEncoder {
|
||||||
static String encodeHighLevel(String msg, Compaction compaction, Charset encoding, boolean autoECI)
|
static String encodeHighLevel(String msg, Compaction compaction, Charset encoding, boolean autoECI)
|
||||||
throws WriterException {
|
throws WriterException {
|
||||||
|
|
||||||
|
if (msg.isEmpty()) {
|
||||||
|
throw new WriterException("Empty message not allowed");
|
||||||
|
}
|
||||||
|
|
||||||
if (encoding == null && !autoECI) {
|
if (encoding == null && !autoECI) {
|
||||||
for (int i = 0; i < msg.length(); i++) {
|
for (int i = 0; i < msg.length(); i++) {
|
||||||
if (msg.charAt(i) > 255) {
|
if (msg.charAt(i) > 255) {
|
||||||
|
|
|
@ -16,6 +16,8 @@
|
||||||
|
|
||||||
package com.google.zxing.pdf417.encoder;
|
package com.google.zxing.pdf417.encoder;
|
||||||
|
|
||||||
|
import com.google.zxing.WriterException;
|
||||||
|
|
||||||
import java.nio.charset.StandardCharsets;
|
import java.nio.charset.StandardCharsets;
|
||||||
|
|
||||||
import org.junit.Assert;
|
import org.junit.Assert;
|
||||||
|
@ -67,4 +69,8 @@ public final class PDF417EncoderTestCase extends Assert {
|
||||||
assertEquals("\u039f\u001A\u0385abcd", encoded);
|
assertEquals("\u039f\u001A\u0385abcd", encoded);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test(expected = WriterException.class)
|
||||||
|
public void testEncodeEmptyString() throws Exception {
|
||||||
|
PDF417HighLevelEncoder.encodeHighLevel("", Compaction.AUTO, null, false);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue