Skip to content

Commit

Permalink
Avoid use of Encoding.WindowsCodePage
Browse files Browse the repository at this point in the history
Fixes 7612
  • Loading branch information
robmen committed Nov 7, 2023
1 parent b842027 commit 96e9c0f
Show file tree
Hide file tree
Showing 4 changed files with 62 additions and 4 deletions.
6 changes: 3 additions & 3 deletions src/api/wix/WixToolset.Data/ErrorMessages.cs
Original file line number Diff line number Diff line change
Expand Up @@ -867,12 +867,12 @@ public static Message IllegalCharactersInPath(string pathName)

public static Message IllegalCodepage(int codepage)
{
return Message(null, Ids.IllegalCodepage, "The code page '{0}' is not a valid Windows code page. Update the database's code page by modifying one of the following attributes: Package/@Codepage, Module/@Codepage, Patch/@Codepage, PatchCreation/@Codepage, or WixLocalization/@Codepage.", codepage);
return Message(null, Ids.IllegalCodepage, "The code page '{0}' is not a valid Windows code page. Update the database's code page by modifying one of the following attributes: Package/@Codepage, Module/@Codepage, Patch/@Codepage, or WixLocalization/@Codepage.", codepage);
}

public static Message IllegalCodepage(SourceLineNumber sourceLineNumbers, int codepage)
{
return Message(sourceLineNumbers, Ids.IllegalCodepage, "The code page '{0}' is not a valid Windows code page. Update the database's code page by modifying one of the following attributes: Package/@Codepage, Module/@Codepage, Patch/@Codepage, PatchCreation/@Codepage, or WixLocalization/@Codepage.", codepage);
return Message(sourceLineNumbers, Ids.IllegalCodepage, "The code page '{0}' is not a valid Windows code page. Update the database's code page by modifying one of the following attributes: Package/@Codepage, Module/@Codepage, Patch/@Codepage, or WixLocalization/@Codepage.", codepage);
}

public static Message IllegalCodepageAttribute(SourceLineNumber sourceLineNumbers, string codepage, string elementName, string attributeName)
Expand Down Expand Up @@ -1318,7 +1318,7 @@ public static Message InvalidSequenceTable(string sequenceTableName)

public static Message InvalidStringForCodepage(SourceLineNumber sourceLineNumbers, string codepage)
{
return Message(sourceLineNumbers, Ids.InvalidStringForCodepage, "A string was provided with characters that are not available in the specified database code page '{0}'. Either change these characters to ones that exist in the database's code page, or update the database's code page by modifying one of the following attributes: Package/@Codepage, Module/@Codepage, Patch/@Codepage, PatchCreation/@Codepage, or WixLocalization/@Codepage.", codepage);
return Message(sourceLineNumbers, Ids.InvalidStringForCodepage, "A string was provided with characters that are not available in the specified database code page '{0}'. Either change these characters to ones that exist in the database's code page, or update the database's code page by modifying one of the following attributes: Package/@Codepage, Module/@Codepage, Patch/@Codepage, or WixLocalization/@Codepage.", codepage);
}

public static Message InvalidStubExe(string filename)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ private void TableToIdtDefinition(Table table, StreamWriter writer, bool keepAdd
}
catch (EncoderFallbackException)
{
this.Messaging.Write(ErrorMessages.InvalidStringForCodepage(row.SourceLineNumbers, Convert.ToString(writer.Encoding.WindowsCodePage, CultureInfo.InvariantCulture)));
this.Messaging.Write(ErrorMessages.InvalidStringForCodepage(row.SourceLineNumbers, Convert.ToString(writer.Encoding.CodePage, CultureInfo.InvariantCulture)));

rowBytes = convertEncoding.GetBytes(rowString);
}
Expand Down
44 changes: 44 additions & 0 deletions src/wix/test/WixToolsetTest.CoreIntegration/EncodingFixture.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
// Copyright (c) .NET Foundation and contributors. All rights reserved. Licensed under the Microsoft Reciprocal License. See LICENSE.TXT file in the project root for full license information.

namespace WixToolsetTest.CoreIntegration
{
using System.IO;
using System.Linq;
using WixInternal.Core.TestPackage;
using WixInternal.TestSupport;
using WixToolset.Data;
using Xunit;

public class EncodingFixture
{
[Fact]
public void PopulatesAppIdTableWhenAdvertised()
{
var folder = TestData.Get(@"TestData");

using (var fs = new DisposableFileSystem())
{
var baseFolder = fs.GetFolder();
var intermediateFolder = Path.Combine(baseFolder, "obj");
var msiPath = Path.Combine(baseFolder, @"bin", "test.msi");

var result = WixRunner.Execute(new[]
{
"build",
Path.Combine(folder, "Encoding", "Encoding.wxs"),
"-bindpath", Path.Combine(folder, "SingleFile", "data"),
"-intermediateFolder", intermediateFolder,
"-o", msiPath
});

var errors = result.Messages.Where(m => m.Level == MessageLevel.Error).Select(m => m.ToString().Replace(folder, "<testdata>")).ToArray();
WixAssert.CompareLineByLine(new[]
{
"A string was provided with characters that are not available in the specified database code page '1252'. Either change these characters to ones that exist in the database's code page, or update the database's code page by modifying one of the following attributes: Package/@Codepage, Module/@Codepage, Patch/@Codepage, or WixLocalization/@Codepage.",
"A string was provided with characters that are not available in the specified database code page '1252'. Either change these characters to ones that exist in the database's code page, or update the database's code page by modifying one of the following attributes: Package/@Codepage, Module/@Codepage, Patch/@Codepage, or WixLocalization/@Codepage.",
"A string was provided with characters that are not available in the specified database code page '1252'. Either change these characters to ones that exist in the database's code page, or update the database's code page by modifying one of the following attributes: Package/@Codepage, Module/@Codepage, Patch/@Codepage, or WixLocalization/@Codepage.",
}, errors);
}
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
<Wix xmlns="http://wixtoolset.org/schemas/v4/wxs">
<Package Name="Ć Not In 1252 Codepage" Version="3.0.0" Codepage="1252" Manufacturer="Example Company" Language="1033" UpgradeCode="11111111-1111-1111-1111-111111111111">
<StandardDirectory Id="ProgramFiles6432Folder">
<Directory Id="INSTALLFOLDER" Name="test">
</Directory>
</StandardDirectory>

<Feature Id="Main">
<Component Directory="INSTALLFOLDER">
<File Source="test.txt" />
</Component>
</Feature>
</Package>
</Wix>

0 comments on commit 96e9c0f

Please sign in to comment.