Skip to content

Commit

Permalink
Merge pull request #59 from jumpserver/dev
Browse files Browse the repository at this point in the history
v4.4.0
  • Loading branch information
BaiJiangJie authored Nov 21, 2024
2 parents cba4107 + b5ad47a commit f6da3e8
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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(",");
Expand All @@ -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(",");
Expand Down
Original file line number Diff line number Diff line change
@@ -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;
}
}

0 comments on commit f6da3e8

Please sign in to comment.