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

ExceptionHandler 中 Exception 部分返回 body 参数增加 html 转义 #10643

Merged
merged 3 commits into from
Jun 30, 2023

Conversation

DarrenLuo
Copy link
Contributor

relation #10640

Please do not create a Pull Request without creating an issue first.

What is the purpose of the change

在 ExceptionHandler 中,返回的数据如果存在 html 标签,则可能导致前端出现一些特殊情况,所以对于未知的 Exception 返回 body 部分增加 html 转义

Brief changelog

XX

Verifying this change

XXXX

Follow this checklist to help us incorporate your contribution quickly and easily:

  • Make sure there is a Github issue filed for the change (usually before you start working on it). Trivial changes like typos do not require a Github issue. Your pull request should address just this issue, without pulling in other changes - one PR resolves one issue.
  • Format the pull request title like [ISSUE #123] Fix UnknownException when host config not exist. Each commit in the pull request should have a meaningful subject line and body.
  • Write a pull request description that is detailed enough to understand what the pull request does, how, and why.
  • Write necessary unit-test to verify your logic correction, more mock a little better when cross module dependency exist. If the new feature or significant change is committed, please remember to add integration-test in test module.
  • Run mvn -B clean package apache-rat:check findbugs:findbugs -Dmaven.test.skip=true to make sure basic checks pass. Run mvn clean install -DskipITs to make sure unit-test pass. Run mvn clean test-compile failsafe:integration-test to make sure integration-test pass.

@ExceptionHandler(IllegalArgumentException.class)
private ResponseEntity<String> handleIllegalArgumentException(IllegalArgumentException e) {
return ResponseEntity.status(HttpStatus.BAD_REQUEST).body(ExceptionUtil.getAllExceptionMsg(e));
}

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please don't change the indent. Use nacos code style to reformat codes.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Handled

@codecov-commenter
Copy link

Codecov Report

Merging #10643 (c990dba) into develop (44115d8) will increase coverage by 0.00%.
The diff coverage is 0.00%.

Additional details and impacted files

Impacted file tree graph

@@            Coverage Diff             @@
##             develop   #10643   +/-   ##
==========================================
  Coverage      53.60%   53.60%           
- Complexity      5516     5517    +1     
==========================================
  Files            897      897           
  Lines          28811    28812    +1     
  Branches        3161     3161           
==========================================
+ Hits           15444    15445    +1     
- Misses         12018    12019    +1     
+ Partials        1349     1348    -1     
Impacted Files Coverage Δ
...cos/console/exception/ConsoleExceptionHandler.java 0.00% <0.00%> (ø)

... and 1 file with indirect coverage changes


Continue to review full report in Codecov by Sentry.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 1311df0...c990dba. Read the comment docs.

}
return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).body(ExceptionUtil.getAllExceptionMsg(e));
return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR)
.body(HtmlUtils.htmlEscape(ExceptionUtil.getAllExceptionMsg(e), "utf-8"));
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why directly set utf-8?

@DarrenLuo
Copy link
Contributor Author

这里是提供给 HtmlUtils.htmlEscape 方法使用的,如果不设置的话默认是 iso-8859-1,会导致西文之外的字符集乱码
1687942636139_48DA8745-A755-44f0-BFD1-E39AF4AD7CA7

@KomachiSion KomachiSion merged commit 4e64f7f into alibaba:develop Jun 30, 2023
wukong121 pushed a commit to wukong121/nacos that referenced this pull request Aug 4, 2023
* ExceptionHandler 中 Exception 部分返回 body 参数增加 html 转义

* 根据 nacos code style 重新格式化该文件
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants