diff --git a/cache/src/main/scala/coursier/Cache.scala b/cache/src/main/scala/coursier/Cache.scala index e176d5d27..4f61a32be 100644 --- a/cache/src/main/scala/coursier/Cache.scala +++ b/cache/src/main/scala/coursier/Cache.scala @@ -832,6 +832,8 @@ object Cache { } } + private val utf8Bom = "\ufeff" + def fetch( cache: File = default, cachePolicy: CachePolicy = CachePolicy.FetchMissing, @@ -853,7 +855,9 @@ object Cache { val res = if (!f.isDirectory && f.exists()) { Try(new String(NioFiles.readAllBytes(f.toPath), "UTF-8")) match { case scala.util.Success(content) => - Right(content) + // stripping any UTF-8 BOM if any, see + // https://github.com/alexarchambault/coursier/issues/316 and the corresponding test + Right(content.stripPrefix(utf8Bom)) case scala.util.Failure(e) => Left(s"Could not read (file:${f.getCanonicalPath}): ${e.getMessage}") } diff --git a/tests/shared/src/test/resources/resolutions/dk.brics.automaton/automaton/1.11-8 b/tests/shared/src/test/resources/resolutions/dk.brics.automaton/automaton/1.11-8 new file mode 100644 index 000000000..967d4c082 --- /dev/null +++ b/tests/shared/src/test/resources/resolutions/dk.brics.automaton/automaton/1.11-8 @@ -0,0 +1 @@ +dk.brics.automaton:automaton:1.11-8:compile diff --git a/tests/shared/src/test/scala/coursier/test/CentralTests.scala b/tests/shared/src/test/scala/coursier/test/CentralTests.scala index 1be4109c9..d9a5022f2 100644 --- a/tests/shared/src/test/scala/coursier/test/CentralTests.scala +++ b/tests/shared/src/test/scala/coursier/test/CentralTests.scala @@ -399,6 +399,13 @@ object CentralTests extends TestSuite { } } } + + 'ignoreUtf8Bom - { + resolutionCheck( + Module("dk.brics.automaton", "automaton"), + "1.11-8" + ) + } } }