You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@royale.apache.org by jo...@apache.org on 2022/07/14 23:12:24 UTC

[royale-compiler] 05/06: formatter: fix invalid error detected when source file starts with UTF BOM character

This is an automated email from the ASF dual-hosted git repository.

joshtynjala pushed a commit to branch develop
in repository https://gitbox.apache.org/repos/asf/royale-compiler.git

commit 2b6bf3e5e65c818e96caa67241b426fe6a610728
Author: Josh Tynjala <jo...@apache.org>
AuthorDate: Thu Jul 14 11:35:42 2022 -0700

    formatter: fix invalid error detected when source file starts with UTF BOM character
---
 .../src/main/java/org/apache/royale/formatter/FORMATTER.java     | 9 ++++++---
 1 file changed, 6 insertions(+), 3 deletions(-)

diff --git a/formatter/src/main/java/org/apache/royale/formatter/FORMATTER.java b/formatter/src/main/java/org/apache/royale/formatter/FORMATTER.java
index 35c0d04a0..a512c0987 100644
--- a/formatter/src/main/java/org/apache/royale/formatter/FORMATTER.java
+++ b/formatter/src/main/java/org/apache/royale/formatter/FORMATTER.java
@@ -41,6 +41,7 @@ import org.apache.royale.compiler.clients.problems.ProblemQuery;
 import org.apache.royale.compiler.clients.problems.WorkspaceProblemFormatter;
 import org.apache.royale.compiler.common.VersionInfo;
 import org.apache.royale.compiler.exceptions.ConfigurationException;
+import org.apache.royale.compiler.filespecs.FileSpecification;
 import org.apache.royale.compiler.internal.config.localization.LocalizationManager;
 import org.apache.royale.compiler.internal.parsing.as.ASParser;
 import org.apache.royale.compiler.internal.parsing.as.ASToken;
@@ -169,7 +170,8 @@ public class FORMATTER {
 				} else {
 					for (File inputFile : inputFiles) {
 						String filePath = FilenameNormalization.normalize(inputFile.getAbsolutePath());
-						String fileText = FileUtils.readFileToString(inputFile, "utf8");
+						FileSpecification fileSpec = new FileSpecification(filePath);
+						String fileText = IOUtils.toString(fileSpec.createReader());
 						String formattedText = formatFileText(filePath, fileText, problemQuery.getProblems());
 						if (!fileText.equals(formattedText)) {
 							if (listChangedFiles) {
@@ -206,8 +208,9 @@ public class FORMATTER {
 	}
 
 	public String formatFile(File file, Collection<ICompilerProblem> problems) throws IOException {
-		String fileText = FileUtils.readFileToString(file, "utf8");
-		String filePath = file.getAbsolutePath();
+		String filePath = FilenameNormalization.normalize(file.getAbsolutePath());
+		FileSpecification fileSpec = new FileSpecification(filePath);
+		String fileText = IOUtils.toString(fileSpec.createReader());
 		return formatFileText(filePath, fileText, problems);
 	}