diff --git a/build.sbt b/build.sbt index 128209168..b07d436cf 100644 --- a/build.sbt +++ b/build.sbt @@ -2,7 +2,7 @@ lazy val commonSettings = Seq( scalacOptions ++= commonScalacOptions, scalaVersion := "2.12.15", organization := "org.ergoplatform", - version := "9.16.5", + version := "9.16.6", resolvers += Resolver.sonatypeRepo("public"), resolvers += Resolver.sonatypeRepo("snapshots"), libraryDependencies ++= dependencies.Testing ++ dependencies.CompilerPlugins, diff --git a/modules/explorer-core/src/main/scala/org/ergoplatform/explorer/protocol/TokenPropsParser.scala b/modules/explorer-core/src/main/scala/org/ergoplatform/explorer/protocol/TokenPropsParser.scala index 164548e5c..929c1b2db 100644 --- a/modules/explorer-core/src/main/scala/org/ergoplatform/explorer/protocol/TokenPropsParser.scala +++ b/modules/explorer-core/src/main/scala/org/ergoplatform/explorer/protocol/TokenPropsParser.scala @@ -30,10 +30,11 @@ object TokenPropsParser { val nameRaw = r4 >>= parse val nameOpt = nameRaw >>= (raw => toUtf8String(raw.toArray)) nameOpt.map { name => - val descriptionRaw = r5 >>= parse - val decimalsRaw = r6 >>= parse - val descriptionOpt = descriptionRaw >>= (raw => toUtf8String(raw.toArray)) - val decimalsOpt = decimalsRaw >>= (raw => toUtf8String(raw.toArray).map(_.toInt)) + val descriptionRaw = r5 >>= parse + val decimalsRaw = r6 >>= parse + val descriptionOpt = descriptionRaw >>= (raw => toUtf8String(raw.toArray)) + val decimalsOpt = + Try(decimalsRaw >>= (raw => toUtf8String(raw.toArray).map(_.toInt))).toOption.flatten val (description, decimals) = (descriptionOpt.getOrElse(""), decimalsOpt.getOrElse(0)) TokenPropsEip4(name, description, decimals) } @@ -41,7 +42,8 @@ object TokenPropsParser { } private def looksLikeUTF8(utf8: Array[Byte]): Boolean = { - val p = Pattern.compile("\\A(\n" + + val p = Pattern.compile( + "\\A(\n" + " [\\x09\\x0A\\x0D\\x20-\\x7E] # ASCII\\n" + "| [\\xC2-\\xDF][\\x80-\\xBF] # non-overlong 2-byte\n" + "| \\xE0[\\xA0-\\xBF][\\x80-\\xBF] # excluding overlongs\n" + @@ -50,14 +52,15 @@ object TokenPropsParser { "| \\xF0[\\x90-\\xBF][\\x80-\\xBF]{2} # planes 1-3\n" + "| [\\xF1-\\xF3][\\x80-\\xBF]{3} # planes 4-15\n" + "| \\xF4[\\x80-\\x8F][\\x80-\\xBF]{2} # plane 16\n" + - ")*\\z", Pattern.COMMENTS) + ")*\\z", + Pattern.COMMENTS + ) val phonyString = new String(utf8, "ISO-8859-1") p.matcher(phonyString).matches } - private def toUtf8String(raw: Array[Byte]): Option[String] = { + private def toUtf8String(raw: Array[Byte]): Option[String] = if (looksLikeUTF8(raw)) Try(new String(raw, Eip4StringCharset)).toOption else None - } }