diff --git a/backend/framework/src/main/java/org/jumpserver/chen/framework/console/dataview/DataView.java b/backend/framework/src/main/java/org/jumpserver/chen/framework/console/dataview/DataView.java index 8a3e774..890d427 100644 --- a/backend/framework/src/main/java/org/jumpserver/chen/framework/console/dataview/DataView.java +++ b/backend/framework/src/main/java/org/jumpserver/chen/framework/console/dataview/DataView.java @@ -12,11 +12,13 @@ import org.jumpserver.chen.framework.datasource.sql.SQLQueryResult; import org.jumpserver.chen.framework.jms.entity.CommandRecord; import org.jumpserver.chen.framework.session.SessionManager; +import org.jumpserver.chen.framework.utils.CodeUtils; import org.jumpserver.chen.framework.ws.io.PacketIO; import java.io.BufferedWriter; import java.io.IOException; import java.nio.file.Files; +import java.sql.Clob; import java.sql.SQLException; import java.time.LocalDateTime; import java.time.format.DateTimeFormatter; @@ -164,6 +166,9 @@ public void export(String scope) throws SQLException { if (row.get(field.getName()) == null) { writer.write("NULL"); writer.write(","); + } else if (row.get(field.getName()) instanceof Clob clob) { + writer.write(CodeUtils.escapeCsvValue(clob.getSubString(1, (int) clob.length()))); + writer.write(","); } else { writeString(writer, row.get(field.getName())); writer.write(","); @@ -190,6 +195,9 @@ public void export(String scope) throws SQLException { if (o == null) { writer.write("NULL"); writer.write(","); + } else if (o instanceof Clob clob) { + writer.write(CodeUtils.escapeCsvValue(clob.getSubString(1, (int) clob.length()))); + writer.write(","); } else { writer.write(o.toString()); writer.write(","); diff --git a/backend/framework/src/main/java/org/jumpserver/chen/framework/utils/CodeUtils.java b/backend/framework/src/main/java/org/jumpserver/chen/framework/utils/CodeUtils.java new file mode 100644 index 0000000..f462447 --- /dev/null +++ b/backend/framework/src/main/java/org/jumpserver/chen/framework/utils/CodeUtils.java @@ -0,0 +1,20 @@ +package org.jumpserver.chen.framework.utils; + + +public class CodeUtils { + + /** + * 对导出文件的换行符进行转义 + * @param value + * @return + */ + public static String escapeCsvValue(String value) { + if (value.contains("\"") || value.contains(",") || value.contains("\n")) { + // 对引号进行转义 + value = value.replace("\"", "\"\""); + // 用引号包围值 + value = "\"" + value + "\""; + } + return value; + } +}