Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

2.0.0-ALPHA.1 ConfigQueryRequestHandler.readFileContent miss line char. 读配置丢失换行符 #4681

Closed
CherishCai opened this issue Jan 13, 2021 · 3 comments
Assignees
Labels
area/Config kind/bug Category issues or prs related to bug. version/2.x
Milestone

Comments

@CherishCai
Copy link
Contributor

Describe the bug
ConfigQueryRequestHandler.readFileContent miss line char.
读配置丢失换行符

Expected behavior
Restore the original configuration content.
还原为原本的配置,直接 read 字节后转成字符串为最佳?

Acutally behavior
The newline character is lost, and the configuration content is inconsistent with the server after it is returned to the client MD5.
丢失换行符,配置内容返回客户端 md5 后与服务端不一致。

Additional context
That's what I'm dealing with right now.
暂时如此处理,但内容该是返璞归真。

config/src/main/java/com/alibaba/nacos/config/server/remote/ConfigQueryRequestHandler.java

public static String readFileContent(File file) {

        StringBuilder sb = new StringBuilder();
        try (BufferedReader reader = new BufferedReader(new FileReader(file))) {

            String tempStr;
            while ((tempStr = reader.readLine()) != null) {
                // FIXME readLine lose '\n', It may not be restored because the content is inconsistent. The MD5 value of the client is different from that of the server
                sb.append(tempStr).append('\n');
            }
            sb.setLength(sb.length() - 1);

            return sb.toString();
        } catch (IOException e) {
            e.printStackTrace();
        }
        return sb.toString();
    }
@CherishCai CherishCai changed the title ConfigQueryRequestHandler.readFileContent miss line char. 读配置丢失换行符 2.0.0-ALPHA.1 ConfigQueryRequestHandler.readFileContent miss line char. 读配置丢失换行符 Jan 13, 2021
@CherishCai
Copy link
Contributor Author

org.apache.commons.io.FileUtils.readFileToString(file);

@shiyiyue1102
Copy link
Collaborator

Describe the bug
ConfigQueryRequestHandler.readFileContent miss line char.
读配置丢失换行符

Expected behavior
Restore the original configuration content.
还原为原本的配置,直接 read 字节后转成字符串为最佳?

Acutally behavior
The newline character is lost, and the configuration content is inconsistent with the server after it is returned to the client MD5.
丢失换行符,配置内容返回客户端 md5 后与服务端不一致。

Additional context
That's what I'm dealing with right now.
暂时如此处理,但内容该是返璞归真。

config/src/main/java/com/alibaba/nacos/config/server/remote/ConfigQueryRequestHandler.java

public static String readFileContent(File file) {

        StringBuilder sb = new StringBuilder();
        try (BufferedReader reader = new BufferedReader(new FileReader(file))) {

            String tempStr;
            while ((tempStr = reader.readLine()) != null) {
                // FIXME readLine lose '\n', It may not be restored because the content is inconsistent. The MD5 value of the client is different from that of the server
                sb.append(tempStr).append('\n');
            }
            sb.setLength(sb.length() - 1);

            return sb.toString();
        } catch (IOException e) {
            e.printStackTrace();
        }
        return sb.toString();
    }

OK,I have reproduce this bug local ,thank you very much to report this bug.

@KomachiSion KomachiSion added kind/bug Category issues or prs related to bug. and removed kind/research labels Jan 13, 2021
@KomachiSion KomachiSion added this to the 2.0.0 milestone Jan 13, 2021
@CherishCai
Copy link
Contributor Author

image

image

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area/Config kind/bug Category issues or prs related to bug. version/2.x
Projects
None yet
Development

No branches or pull requests

4 participants