Skip to content

Commit a3c3e64

Browse files
committed
Normalize JSON5 upsert as text upsert to properly replicate JSON5 content
1 parent e0f6fbb commit a3c3e64

File tree

3 files changed

+6
-5
lines changed

3 files changed

+6
-5
lines changed

common/src/main/java/com/linecorp/centraldogma/common/Change.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ static Change<String> ofTextUpsert(String path, byte[] content) {
8484
static Change<String> ofTextUpsert(String path, String text) {
8585
requireNonNull(text, "text");
8686
validateFilePath(path, "path");
87-
if (EntryType.guessFromPath(path) == EntryType.JSON) {
87+
if (EntryType.guessFromPath(path) == EntryType.JSON && !isJson5(path)) {
8888
throw new ChangeFormatException("invalid file type: " + path +
8989
" (expected: a non-JSON file). Use Change.ofJsonUpsert() instead");
9090
}

it/src/test/java/com/linecorp/centraldogma/it/TestConstants.java

-2
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,6 @@
1919
import static java.util.Objects.requireNonNull;
2020

2121
import java.io.File;
22-
import java.io.IOException;
23-
import java.net.URISyntaxException;
2422
import java.net.URL;
2523
import java.nio.charset.StandardCharsets;
2624
import java.nio.file.Files;

server/src/main/java/com/linecorp/centraldogma/server/internal/storage/repository/git/GitRepository.java

+5-2
Original file line numberDiff line numberDiff line change
@@ -754,7 +754,7 @@ private Map<String, Change<?>> toChangeMap(List<DiffEntry> diffEntryList) {
754754
switch (diffEntry.getChangeType()) {
755755
case MODIFY:
756756
// Resolve JSON5 as EntryType.TEXT to modify it with text patch because
757-
// json patch can hardly be applied to JSON5.
757+
// applying json patch to JSON5 file makes it a plain JSON.
758758
final EntryType oldEntryType = !isJson5(oldPath) ? EntryType.guessFromPath(oldPath)
759759
: EntryType.TEXT;
760760
switch (oldEntryType) {
@@ -798,7 +798,10 @@ private Map<String, Change<?>> toChangeMap(List<DiffEntry> diffEntryList) {
798798
}
799799
break;
800800
case ADD:
801-
final EntryType newEntryType = EntryType.guessFromPath(newPath);
801+
// Resolve JSON5 as EntryType.TEXT so that the JSON5 content can properly be included
802+
// in the serialized ReplicationLog.
803+
final EntryType newEntryType = !isJson5(newPath) ? EntryType.guessFromPath(newPath)
804+
: EntryType.TEXT;
802805
switch (newEntryType) {
803806
case JSON: {
804807
final String jsonText = new String(

0 commit comments

Comments
 (0)