From 8b7a624fcfd939dedf02af91dc2e82e016e1c20a Mon Sep 17 00:00:00 2001 From: Mukul Sabharwal Date: Sat, 19 Nov 2016 11:12:05 -0800 Subject: [PATCH] Fix fallback encoding case; canBeEmbedded was not propogated --- .../Core/CodeAnalysisTest/EmbeddedTextTests.cs | 11 +++++++++++ src/Compilers/Core/Portable/EncodedStringText.cs | 2 +- 2 files changed, 12 insertions(+), 1 deletion(-) diff --git a/src/Compilers/Core/CodeAnalysisTest/EmbeddedTextTests.cs b/src/Compilers/Core/CodeAnalysisTest/EmbeddedTextTests.cs index e204c908a42..f5dea53aa88 100644 --- a/src/Compilers/Core/CodeAnalysisTest/EmbeddedTextTests.cs +++ b/src/Compilers/Core/CodeAnalysisTest/EmbeddedTextTests.cs @@ -244,6 +244,17 @@ public void FromSource_Precomputed() } } + [Fact] + public void FromBytes_EncodingFallbackCase() + { + var source = EncodedStringText.Create(new MemoryStream(new byte[] { 0xA9, 0x0D, 0x0A }), canBeEmbedded: true); + var text = EmbeddedText.FromSource("pathToLarge", source); + + Assert.Equal("pathToLarge", text.FilePath); + Assert.Equal(SourceHashAlgorithm.Sha1, text.ChecksumAlgorithm); + AssertEx.Equal(source.GetChecksum(), text.Checksum); + } + private byte[] Decompress(IEnumerable bytes) { var destination = new MemoryStream(); diff --git a/src/Compilers/Core/Portable/EncodedStringText.cs b/src/Compilers/Core/Portable/EncodedStringText.cs index 871a0870498..21d5caf4e02 100644 --- a/src/Compilers/Core/Portable/EncodedStringText.cs +++ b/src/Compilers/Core/Portable/EncodedStringText.cs @@ -104,7 +104,7 @@ private static Encoding GetFallbackEncoding() try { - return Decode(stream, defaultEncoding ?? getEncoding.Value, checksumAlgorithm, throwIfBinaryDetected: detectEncoding); + return Decode(stream, defaultEncoding ?? getEncoding.Value, checksumAlgorithm, throwIfBinaryDetected: detectEncoding, canBeEmbedded: canBeEmbedded); } catch (DecoderFallbackException e) { -- GitLab