Skip to content

Commit

Permalink
fix latin1 non-ascii error, for issue #1277
Browse files Browse the repository at this point in the history
  • Loading branch information
wenshao committed Mar 25, 2023
1 parent 12674c8 commit d0b37a7
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 3 deletions.
6 changes: 3 additions & 3 deletions core/src/main/java/com/alibaba/fastjson2/JSONReaderASCII.java
Original file line number Diff line number Diff line change
Expand Up @@ -806,7 +806,7 @@ public String getFieldName() {

int offset = nameBegin;
for (int i = 0; offset < nameEnd; ++i) {
char c = (char) bytes[offset];
char c = (char) (bytes[offset] & 0xff);

if (c == '\\') {
c = (char) bytes[++offset];
Expand Down Expand Up @@ -1209,7 +1209,7 @@ protected void readString0() {
char[] chars = new char[valueLength];
offset = start;
for (int i = 0; ; ++i) {
char c = (char) bytes[offset];
char c = (char) (bytes[offset] & 0xff);
if (c == '\\') {
c = (char) (bytes[++offset]);
switch (c) {
Expand Down Expand Up @@ -1357,7 +1357,7 @@ public String readString() {
char[] chars = new char[valueLength];
offset = start;
for (int i = 0; ; ++i) {
char c = (char) bytes[offset];
char c = (char) (bytes[offset] & 0xff);
if (c == '\\') {
c = (char) bytes[++offset];
switch (c) {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
package com.alibaba.fastjson2.issues_1000;

import com.alibaba.fastjson2.JSON;
import com.alibaba.fastjson2.JSONObject;
import org.junit.jupiter.api.Test;

import java.util.HashMap;
import java.util.Map;

import static org.junit.jupiter.api.Assertions.assertEquals;

public class Issue1277 {
@Test
public void test() {
Map<String, String> params = new HashMap<>();
params.put("name", "{\"paternalSurname\": \"Rodríguez\"}");
String json = JSON.toJSONString(params);
System.out.println(json);
JSONObject jsonObject = JSON.parseObject(json);
// output: {"name":"{\"paternalSurname\": \"Rodr■guez\"}"}
// Rodríguez 变成了 Rodr■guez
assertEquals(params.get("name"), jsonObject.get("name"));
}
}

0 comments on commit d0b37a7

Please sign in to comment.