You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@shardingsphere.apache.org by "sandynz (via GitHub)" <gi...@apache.org> on 2023/02/08 05:14:11 UTC

[GitHub] [shardingsphere] sandynz commented on a diff in pull request #24049: Fix unicode cannot be decoded correctly at TestDecodingPlugin

sandynz commented on code in PR #24049:
URL: https://github.com/apache/shardingsphere/pull/24049#discussion_r1099655201


##########
kernel/data-pipeline/dialect/postgresql/src/main/java/org/apache/shardingsphere/data/pipeline/postgresql/ingest/wal/decode/TestDecodingPlugin.java:
##########
@@ -208,26 +211,60 @@ private String readNextSegment(final ByteBuffer data) {
         return eventType.toString();
     }
     
+    private String readNextJson(final ByteBuffer data) {
+        data.get();
+        int offset = 0;
+        int startPosition = data.position();
+        while (data.hasRemaining()) {
+            char c = (char) data.get();
+            if ('}' != c) {

Review Comment:
   `c`, `c2` and `c3` could be removed and embedded in `if` condition



##########
kernel/data-pipeline/dialect/postgresql/src/main/java/org/apache/shardingsphere/data/pipeline/postgresql/ingest/wal/decode/TestDecodingPlugin.java:
##########
@@ -208,26 +211,60 @@ private String readNextSegment(final ByteBuffer data) {
         return eventType.toString();
     }
     
+    private String readNextJson(final ByteBuffer data) {
+        data.get();
+        int offset = 0;
+        int startPosition = data.position();
+        while (data.hasRemaining()) {
+            char c = (char) data.get();
+            if ('}' != c) {
+                offset++;
+                continue;
+            }
+            char c2 = (char) data.get();
+            if ('\'' != c2) {
+                offset++;
+                continue;
+            }
+            char c3 = (char) data.get();
+            if (' ' == c3) {

Review Comment:
   If json text contains `' '` (blank char), then does the parsing work?



##########
kernel/data-pipeline/dialect/postgresql/src/main/java/org/apache/shardingsphere/data/pipeline/postgresql/ingest/wal/decode/TestDecodingPlugin.java:
##########
@@ -208,26 +211,60 @@ private String readNextSegment(final ByteBuffer data) {
         return eventType.toString();
     }
     
+    private String readNextJson(final ByteBuffer data) {

Review Comment:
   It's better to set more complicated json text in E2E



##########
kernel/data-pipeline/dialect/postgresql/src/main/java/org/apache/shardingsphere/data/pipeline/postgresql/ingest/wal/decode/TestDecodingPlugin.java:
##########
@@ -208,26 +211,60 @@ private String readNextSegment(final ByteBuffer data) {
         return eventType.toString();
     }
     
+    private String readNextJson(final ByteBuffer data) {
+        data.get();
+        int offset = 0;
+        int startPosition = data.position();
+        while (data.hasRemaining()) {
+            char c = (char) data.get();
+            if ('}' != c) {
+                offset++;
+                continue;
+            }
+            char c2 = (char) data.get();
+            if ('\'' != c2) {
+                offset++;
+                continue;
+            }
+            char c3 = (char) data.get();
+            if (' ' == c3) {
+                offset++;
+                return getStringSegment(data, startPosition, offset).replace("''", "'");
+            }
+            offset++;
+        }
+        return null;
+    }
+    
+    private String getStringSegment(final ByteBuffer data, final int startPosition, final int offset) {

Review Comment:
   `getStringSegment` could be `readStringSegment`, keep consistent with other methods name



-- 
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@shardingsphere.apache.org

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