Skip to content

Commit 646835f

Browse files
committed
Force reading of title, artist and isrc as UTF-8
1 parent 16f1e9f commit 646835f

File tree

2 files changed

+15
-7
lines changed

2 files changed

+15
-7
lines changed

main/src/main/java/com/sedmelluq/discord/lavaplayer/container/matroska/MatroskaStreamingFile.java

+6-4
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55

66
import java.io.IOException;
77
import java.nio.ByteBuffer;
8+
import java.nio.charset.StandardCharsets;
89
import java.util.ArrayList;
910
import java.util.Arrays;
1011
import java.util.List;
@@ -400,7 +401,7 @@ private void parseSegmentInfo(MatroskaElement infoElement) throws IOException {
400401
} else if (child.is(MatroskaElementType.TimecodeScale)) {
401402
timecodeScale = reader.asLong(child);
402403
} else if (child.is(MatroskaElementType.Title) && title == null) {
403-
title = reader.asString(child);
404+
title = reader.asString(child, StandardCharsets.UTF_8);
404405
}
405406

406407
reader.skip(child);
@@ -453,11 +454,12 @@ private void parseSimpleTag(MatroskaElement simpleTagElement) throws IOException
453454
} else if (child.is(MatroskaElementType.TagString)) {
454455
// https://www.matroska.org/technical/tagging.html
455456
if ("title".equalsIgnoreCase(tagName) && title == null) {
456-
title = reader.asString(child);
457+
title = reader.asString(child, StandardCharsets.UTF_8);
457458
} else if ("artist".equalsIgnoreCase(tagName)) {
458-
artist = reader.asString(child);
459+
artist = reader.asString(child, StandardCharsets.UTF_8);
459460
} else if ("isrc".equalsIgnoreCase(tagName)) {
460-
isrc = reader.asString(child);
461+
// probably not necessary to force a charset here
462+
isrc = reader.asString(child, StandardCharsets.UTF_8);
461463
}
462464
}
463465
}

main/src/main/java/com/sedmelluq/discord/lavaplayer/container/matroska/format/MatroskaFileReader.java

+9-3
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
import java.io.DataInput;
66
import java.io.DataInputStream;
77
import java.io.IOException;
8+
import java.nio.charset.Charset;
89
import java.nio.charset.StandardCharsets;
910

1011
/**
@@ -153,16 +154,21 @@ public double asDouble(MatroskaElement element) throws IOException {
153154
}
154155
}
155156

157+
public String asString(MatroskaElement element) throws IOException {
158+
return asString(element, null);
159+
}
160+
156161
/**
157162
* @param element Element to read from
163+
* @param forceCharset The charset to use, or null for default.
158164
* @return The contents of the element as a string
159165
* @throws IOException On read error
160166
*/
161-
public String asString(MatroskaElement element) throws IOException {
167+
public String asString(MatroskaElement element, Charset forceCharset) throws IOException {
162168
if (element.is(MatroskaElementType.DataType.STRING)) {
163-
return new String(asBytes(element), StandardCharsets.US_ASCII);
169+
return new String(asBytes(element), forceCharset != null ? forceCharset : StandardCharsets.US_ASCII);
164170
} else if (element.is(MatroskaElementType.DataType.UTF8_STRING)) {
165-
return new String(asBytes(element), StandardCharsets.UTF_8);
171+
return new String(asBytes(element), forceCharset != null ? forceCharset : StandardCharsets.UTF_8);
166172
} else {
167173
throw new IllegalArgumentException("Not a string element.");
168174
}

0 commit comments

Comments
 (0)