Skip to content

Commit

Permalink
Use NameTransformer to unmangle symbolic names, fixes 1075
Browse files Browse the repository at this point in the history
  • Loading branch information
Joni Freeman committed Jul 23, 2011
1 parent f24ceaa commit 1c9629e
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 15 deletions.
8 changes: 1 addition & 7 deletions core/json/src/main/scala/net/liftweb/json/Meta.scala
Original file line number Diff line number Diff line change
Expand Up @@ -184,16 +184,10 @@ private[json] object Meta {
}

private[json] def unmangleName(name: String) =
unmangledNames.memoize(name, operators.foldLeft(_)((n, o) => n.replace(o._1, o._2)))
unmangledNames.memoize(name, scala.reflect.NameTransformer.decode)

private[json] def fail(msg: String, cause: Exception = null) = throw new MappingException(msg, cause)

private val operators = Map(
"$eq" -> "=", "$greater" -> ">", "$less" -> "<", "$plus" -> "+", "$minus" -> "-",
"$times" -> "*", "$div" -> "/", "$bang" -> "!", "$at" -> "@", "$hash" -> "#",
"$percent" -> "%", "$up" -> "^", "$amp" -> "&", "$tilde" -> "~", "$qmark" -> "?",
"$bar" -> "|", "$bslash" -> "\\")

private class Memo[A, R] {
private var cache = Map[A, R]()

Expand Down
10 changes: 6 additions & 4 deletions core/json/src/test/scala/net/liftweb/json/ExtractionBugs.scala
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,6 @@ package json

import org.specs.Specification


/**
* System under specification for Extraction bugs.
*/
object ExtractionBugs extends Specification("Extraction bugs Specification") {
implicit val formats = DefaultFormats

Expand All @@ -48,6 +44,10 @@ object ExtractionBugs extends Specification("Extraction bugs Specification") {
extracted mustEqual ExtractWithAnyRef()
}

"Extraction should work with unicode encoded field names (issue 1075)" in {
parse("""{"foo.bar,baz":"x"}""").extract[UnicodeFieldNames] mustEqual UnicodeFieldNames("x")
}

case class OptionOfInt(opt: Option[Int])

case class PMap(m: Map[String, List[String]])
Expand All @@ -59,4 +59,6 @@ object ExtractionBugs extends Specification("Extraction bugs Specification") {
}

case class ExtractWithAnyRef()

case class UnicodeFieldNames(`foo.bar,baz`: String)
}
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,6 @@ package json
import java.util.Date
import org.specs.Specification


/**
* Systems under specification for Extraction Examples.
*/
object ExtractionExamples extends Specification("Extraction Examples Specification") {
implicit val formats = DefaultFormats

Expand Down

0 comments on commit 1c9629e

Please sign in to comment.