You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@james.apache.org by GitBox <gi...@apache.org> on 2021/11/29 03:19:42 UTC

[GitHub] [james-project] chibenwa commented on a change in pull request #765: JAMES-3677 BackReference should allow pointing to specific array elements

chibenwa commented on a change in pull request #765:
URL: https://github.com/apache/james-project/pull/765#discussion_r758013853



##########
File path: server/protocols/jmap-rfc-8621/src/test/scala/org/apache/james/jmap/json/BackReferenceTest.scala
##########
@@ -46,12 +46,15 @@ class BackReferenceTest extends AnyWordSpec with Matchers {
   }
 
   "Array element parsing" should {
-    "succeed when poositive" in {
+    "succeed when positive" in {
       ArrayElementPart.parse("[1]") should equal(Some(ArrayElementPart(1)))
     }
     "succeed when zero" in {
       ArrayElementPart.parse("[0]") should equal(Some(ArrayElementPart(0)))

Review comment:
       This sould no longer happen, right?

##########
File path: server/protocols/jmap-rfc-8621/src/main/scala/org/apache/james/jmap/routes/ProcessingContext.scala
##########
@@ -82,14 +84,14 @@ object JsonPath {
         } else if (arrayElementPartPosition == 0) {
           asArrayElementPart(string)
         } else {
-          asArrayElementInAnObject(string, part, arrayElementPartPosition)
+          asArrayElementInAnObject(part, arrayElementPartPosition)
         }
     })
 
   private def asPlainPart(part: String): List[JsonPathPart] = List(PlainPart(part))
 
-  private def asArrayElementInAnObject(string: String, part: String, arrayElementPartPosition: Int): List[JsonPathPart] =
-    ArrayElementPart.parse(string.substring(arrayElementPartPosition))
+  private def asArrayElementInAnObject(part: String, arrayElementPartPosition: Int): List[JsonPathPart] =
+    ArrayElementPart.parse(part.substring(arrayElementPartPosition))

Review comment:
       I think it is because with the previous syntax a JSON path path (what is between `/`) could be both a property with an array element accessor: 2 in 1. (eg `a/b[1]/c` have a `b[1]` part that is actually `property b` + `element 1`).
   
   The right JSON path syntax is simpler and have a 1 to 1 relationship: `a/b/1/c` : we can likely simplify `JsonPath.parse` a looot!

##########
File path: server/protocols/jmap-rfc-8621/src/test/scala/org/apache/james/jmap/json/BackReferenceTest.scala
##########
@@ -98,6 +98,29 @@ class BackReferenceTest extends AnyWordSpec with Matchers {
 
       jsonPath.evaluate(json) should equal(JsSuccess(expected))
     }
+    "succeed when first array element is present in second path" in {
+      val jsonPath = JsonPath.parse("path/0")
+      val json = Json.parse("""{"path":[{"id":"1","code":"a"},{"id":"2","code":"b"},{"id":"3","code":"c"}]}""".stripMargin)
+      val expected = Json.parse("""{"id":"1","code":"a"}""")
+
+      jsonPath.evaluate(json) should equal(JsSuccess(expected))
+    }
+    "succeed when pointing to specific array elements and specific path" in {
+      val jsonPath = JsonPath.parse("path/0/id")

Review comment:
       What happen if I go out of bound eg with `path/4/id`




-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscribe@james.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@james.apache.org
For additional commands, e-mail: notifications-help@james.apache.org