Skip to content

Commit 5631047

Browse files
authored
Merge pull request #132 from edgardmessias/fix_xml_encode
Fixed encoding with xml output (Close #129)
2 parents 0fda765 + 1050e3b commit 5631047

File tree

1 file changed

+13
-4
lines changed

1 file changed

+13
-4
lines changed

src/svn.ts

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -170,12 +170,21 @@ export class Svn {
170170
})
171171
]);
172172

173-
jschardet.MacCyrillicModel.mTypicalPositiveRatio += 0.001;
173+
let encoding = "utf8";
174174

175-
const encodingGuess = jschardet.detect(stdout);
175+
// SVN with '--xml' always return 'UTF-8', and jschardet detects this encoding: 'TIS-620'
176+
if (!args.includes("--xml")) {
177+
jschardet.MacCyrillicModel.mTypicalPositiveRatio += 0.001;
176178

177-
const encoding =
178-
encodingGuess.confidence > 0.8 ? encodingGuess.encoding : "utf8";
179+
const encodingGuess = jschardet.detect(stdout);
180+
181+
if (
182+
encodingGuess.confidence > 0.8 &&
183+
iconv.encodingExists(encodingGuess.encoding)
184+
) {
185+
encoding = encodingGuess.encoding;
186+
}
187+
}
179188

180189
stdout = iconv.decode(stdout, encoding);
181190

0 commit comments

Comments
 (0)