Fix character encoding when reading /test.submit_rule

Instead of forcing a String to UTF-8 and then guessing with the
platform default encoding, pass a Reader through that avoids any
char->byte->char conversion.

Change-Id: I29c2cb400e00784117c1475202581cca855d18ee
This commit is contained in:
Shawn Pearce 2015-04-01 22:19:06 -07:00
parent f1d55a34c4
commit 3a8bce7861
3 changed files with 7 additions and 11 deletions

View File

@ -45,8 +45,6 @@ import org.eclipse.jgit.lib.Repository;
import org.eclipse.jgit.util.RawParseUtils;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.PushbackReader;
import java.io.Reader;
import java.io.StringReader;
@ -154,9 +152,9 @@ public class RulesCache {
return pcm;
}
public PrologMachineCopy loadMachine(String name, InputStream in)
public PrologMachineCopy loadMachine(String name, Reader in)
throws CompileException {
PrologMachineCopy pmc = consultRules(name, new InputStreamReader(in));
PrologMachineCopy pmc = consultRules(name, in);
if (pmc == null) {
throw new CompileException("Cannot consult rules from the stream " + name);
}

View File

@ -55,7 +55,7 @@ import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import java.io.IOException;
import java.io.InputStream;
import java.io.Reader;
import java.nio.file.Files;
import java.nio.file.Path;
import java.util.ArrayList;
@ -205,10 +205,10 @@ public class ProjectState {
* read the provided input stream.
*
* @param name a name of the input stream. Could be any name.
* @param in InputStream to read prolog rules from
* @param in stream to read prolog rules from
* @throws CompileException
*/
public PrologEnvironment newPrologEnvironment(String name, InputStream in)
public PrologEnvironment newPrologEnvironment(String name, Reader in)
throws CompileException {
PrologMachineCopy pmc = rulesCache.loadMachine(name, in);
return envFactory.create(pmc);

View File

@ -16,7 +16,6 @@ package com.google.gerrit.server.project;
import static com.google.common.base.Preconditions.checkArgument;
import static com.google.common.base.Preconditions.checkState;
import static java.nio.charset.StandardCharsets.UTF_8;
import com.google.common.collect.Lists;
import com.google.gerrit.common.Nullable;
@ -45,7 +44,7 @@ import com.googlecode.prolog_cafe.lang.VariableTerm;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import java.io.ByteArrayInputStream;
import java.io.StringReader;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
@ -510,8 +509,7 @@ public class SubmitRuleEvaluator {
if (rule == null) {
env = projectState.newPrologEnvironment();
} else {
env = projectState.newPrologEnvironment(
"stdin", new ByteArrayInputStream(rule.getBytes(UTF_8)));
env = projectState.newPrologEnvironment("stdin", new StringReader(rule));
}
} catch (CompileException err) {
throw new RuleEvalException("Cannot consult rules.pl for "