@joebigelow / wix-1 / commits / 96e9c0f7

Avoid use of Encoding.WindowsCodePage

Fixes 7612

Rob Mensching committed Nov 6, 2023 at 23:08 UTC 96e9c0f76029f27bd1f2a777aca385b29e9ec21a
4 files changed +62 -4
src/api/wix/WixToolset.Data/ErrorMessages.cs
+3 -3
@@ -867,12 +867,12 @@ namespace WixToolset.Data
867
868 public static Message IllegalCodepage(int codepage)
869 {
870 - 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);
870 + 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);
871 }
872
873 public static Message IllegalCodepage(SourceLineNumber sourceLineNumbers, int codepage)
874 {
875 - 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);
875 + 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);
876 }
877
878 public static Message IllegalCodepageAttribute(SourceLineNumber sourceLineNumbers, string codepage, string elementName, string attributeName)
@@ -1318,7 +1318,7 @@ namespace WixToolset.Data
1318
1319 public static Message InvalidStringForCodepage(SourceLineNumber sourceLineNumbers, string codepage)
1320 {
1321 - 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);
1321 + 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);
1322 }
1323
1324 public static Message InvalidStubExe(string filename)
src/wix/WixToolset.Core.WindowsInstaller/Bind/CreateIdtFileCommand.cs
+1 -1
@@ -81,7 +81,7 @@ namespace WixToolset.Core.WindowsInstaller.Bind
81 }
82 catch (EncoderFallbackException)
83 {
84 - this.Messaging.Write(ErrorMessages.InvalidStringForCodepage(row.SourceLineNumbers, Convert.ToString(writer.Encoding.WindowsCodePage, CultureInfo.InvariantCulture)));
84 + this.Messaging.Write(ErrorMessages.InvalidStringForCodepage(row.SourceLineNumbers, Convert.ToString(writer.Encoding.CodePage, CultureInfo.InvariantCulture)));
85
86 rowBytes = convertEncoding.GetBytes(rowString);
87 }
src/wix/test/WixToolsetTest.CoreIntegration/EncodingFixture.cs new
+44
@@ -0,0 +1,44 @@
1 +// 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.
2 +
3 +namespace WixToolsetTest.CoreIntegration
4 +{
5 + using System.IO;
6 + using System.Linq;
7 + using WixInternal.Core.TestPackage;
8 + using WixInternal.TestSupport;
9 + using WixToolset.Data;
10 + using Xunit;
11 +
12 + public class EncodingFixture
13 + {
14 + [Fact]
15 + public void PopulatesAppIdTableWhenAdvertised()
16 + {
17 + var folder = TestData.Get(@"TestData");
18 +
19 + using (var fs = new DisposableFileSystem())
20 + {
21 + var baseFolder = fs.GetFolder();
22 + var intermediateFolder = Path.Combine(baseFolder, "obj");
23 + var msiPath = Path.Combine(baseFolder, @"bin", "test.msi");
24 +
25 + var result = WixRunner.Execute(new[]
26 + {
27 + "build",
28 + Path.Combine(folder, "Encoding", "Encoding.wxs"),
29 + "-bindpath", Path.Combine(folder, "SingleFile", "data"),
30 + "-intermediateFolder", intermediateFolder,
31 + "-o", msiPath
32 + });
33 +
34 + var errors = result.Messages.Where(m => m.Level == MessageLevel.Error).Select(m => m.ToString().Replace(folder, "<testdata>")).ToArray();
35 + WixAssert.CompareLineByLine(new[]
36 + {
37 + "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.",
38 + "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.",
39 + "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.",
40 + }, errors);
41 + }
42 + }
43 + }
44 +}
src/wix/test/WixToolsetTest.CoreIntegration/TestData/Encoding/Encoding.wxs new
+14
@@ -0,0 +1,14 @@
1 +<Wix xmlns="http://wixtoolset.org/schemas/v4/wxs">
2 + <Package Name="Ć Not In 1252 Codepage" Version="3.0.0" Codepage="1252" Manufacturer="Example Company" Language="1033" UpgradeCode="11111111-1111-1111-1111-111111111111">
3 + <StandardDirectory Id="ProgramFiles6432Folder">
4 + <Directory Id="INSTALLFOLDER" Name="test">
5 + </Directory>
6 + </StandardDirectory>
7 +
8 + <Feature Id="Main">
9 + <Component Directory="INSTALLFOLDER">
10 + <File Source="test.txt" />
11 + </Component>
12 + </Feature>
13 + </Package>
14 +</Wix>