【问题描述】
最近在开发的时候遇到这么一个问题,后端将diff格式的字符串发送到前端,前端则将该字符串通过控件diff-to-html来显示。
如下所示:
diffContent = "diff --git a/ces测试123-2.0.txt b/ces测试123-2.0.txt index 448ad29..bed094c 100644 (file) --- a/ces测试123-2.0.txt +++ b/ces测试123-2.0.txt @@ -101,7 +101,7 @@ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. limitations under the License. 4. Redistribution. You may reproduce and distribute copies of the Work or Derivative Works thereof in any medium, with or without modifications, and in Source or Object form, provided that You meet the following conditions: - +4. Redistribution. You may reproduce and distribute copies o Open Source Software Licensed Under the MIT License: ---------------------------------------------------------------------------------------- "
将该字符串直接在前端写死,显示也是没有问题的。
但是,如果是在后端将该字符串通过接口的方式给前端,则上下文无法显示。
正常
不正常情况
后端代码是通过拼接字符串,通过换行的话,是通过拼接 /r/n 来实现的,看起来貌似都没问题。
String contentText = "context"+" ";
【解决方案】
在偶然的机会,发现StringUtils中有一个静态属性 LR,如下所示:
public static final String SPACE = " "; public static final String EMPTY = ""; public static final String LF = " "; public static final String CR = " ";
走投无路,将 以及空格全部都换了,打印至前台发现,居然有效....