mirror of
https://github.com/ViaVersion/ViaVersion.git
synced 2025-04-02 01:36:05 +02:00
Fix accidental float/double NaN parsing in snbt
This commit is contained in:
parent
0a19057606
commit
7cc6eb2b66
@ -277,10 +277,16 @@ final class TagStringReader {
|
||||
result = new LongTag(Long.parseLong(builder.toString()));
|
||||
break;
|
||||
case Tokens.TYPE_FLOAT:
|
||||
result = new FloatTag(Float.parseFloat(builder.toString()));
|
||||
final float floatValue = Float.parseFloat(builder.toString());
|
||||
if (!Float.isNaN(floatValue)) {
|
||||
result = new FloatTag(floatValue);
|
||||
}
|
||||
break;
|
||||
case Tokens.TYPE_DOUBLE:
|
||||
result = new DoubleTag(Double.parseDouble(builder.toString()));
|
||||
final double doubleValue = Double.parseDouble(builder.toString());
|
||||
if (!Double.isNaN(doubleValue)) {
|
||||
result = new DoubleTag(doubleValue);
|
||||
}
|
||||
break;
|
||||
}
|
||||
} catch (final NumberFormatException ex) {
|
||||
|
@ -17,6 +17,7 @@
|
||||
*/
|
||||
package com.viaversion.viaversion.common.nbt;
|
||||
|
||||
import com.github.steveice10.opennbt.tag.builtin.FloatTag;
|
||||
import org.junit.jupiter.api.Assertions;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
@ -42,6 +43,7 @@ public class NBTTagTest {
|
||||
readString("{id:[I;1,2,3,]}");
|
||||
readString("{id:[1,2,3,]}");
|
||||
|
||||
Assertions.assertEquals("NaNd", readString("{id:NaNd}").get("id").getValue());
|
||||
Assertions.assertEquals("2147483649", readString("{id:9000b,thisisastring:2147483649}").get("thisisastring").getValue());
|
||||
Assertions.assertEquals((byte) 1, readString("{thisisabyte:true}").get("thisisabyte").getValue());
|
||||
Assertions.assertEquals((byte) 0, readString("{thisisabyte:false}").get("thisisabyte").getValue());
|
||||
|
Loading…
Reference in New Issue
Block a user