Fix normalized string comparison (#2695)

* Fix normalized string comparison

* Add test
This commit is contained in:
benthecarman 2021-02-19 12:09:55 -06:00 committed by GitHub
parent 477597ea72
commit b30fdf88ca
2 changed files with 11 additions and 0 deletions

View file

@ -5,6 +5,15 @@ import org.bitcoins.testkit.util.BitcoinSUnitTest
class TLVTest extends BitcoinSUnitTest {
"NormalizedString" must "correctly compare" in {
val original =
"G<>\u0006=ẁ7\u007F8<46>\u0001 <20>\u0001z <20>/<2F>\u001F<31><46>\u0001\u0001<30><31>\u0001<30>d\u0012\u0001<30> <20>\u007F<37><46><EFBFBD>\u0001<30>\u0001<30><31>9<EFBFBD>\u0001\u007F<37><46>\u007F\u0001'<27><>\u0001<30>\u001B<31><42><EFBFBD>\u001F"
val normalized =
"G<>\u0006=ẁ7\u007F8<46>\u0001 <20>\u0001z <20>/<2F>\u001F<31><46>\u0001\u0001<30><31>\u0001<30>d\u0012\u0001<30> <20>\u007F<37><46><EFBFBD>\u0001<30>\u0001<30><31>9<EFBFBD>\u0001\u007F<37><46>\u007F\u0001'<27><>\u0001<30>\u001B<31><42><EFBFBD>\u001F"
assert(NormalizedString(original) == NormalizedString(normalized))
}
"TLV" must "have serialization symmetry" in {
forAll(TLVGen.tlv) { tlv =>
assert(TLV(tlv.bytes) == tlv)

View file

@ -325,6 +325,8 @@ case class NormalizedString(private val str: String) extends NetworkElement {
other match {
case otherStr: String =>
normStr == otherStr
case otherNorm: NormalizedString =>
normStr == otherNorm.normStr
case _ => other.equals(str)
}
}