Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit042ba3e

Browse files
authored
[release/10.0.1xx-rc.2] [msbuild] Improve detection of resources that would end up outside the app bundle. (#23920)
Backport of#23919.
1 parentdf0d21f commit042ba3e

File tree

2 files changed

+48
-2
lines changed

2 files changed

+48
-2
lines changed

‎msbuild/Xamarin.MacDev.Tasks/Tasks/CollectBundleResources.cs‎

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -227,8 +227,9 @@ public static bool TryCreateItemWithLogicalName<T> (T task, ITaskItem item, [Not
227227
returnfalse;
228228
}
229229

230-
if(logicalName.StartsWith(".."+Path.DirectorySeparatorChar,StringComparison.Ordinal)){
231-
task.Log.LogError(null,null,null,item.ItemSpec,0,0,0,0,MSBStrings.E0100,logicalName);
230+
// Always check for both windows and non-windows style path separators, because we can get both on either platform.
231+
if(logicalName.StartsWith("..\\",StringComparison.Ordinal)||logicalName.StartsWith("../",StringComparison.Ordinal)){
232+
task.Log.LogWarning(null,null,null,item.ItemSpec,0,0,0,0,MSBStrings.E0100,logicalName);
232233
returnfalse;
233234
}
234235

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
usingSystem;
2+
usingSystem.Collections.Generic;
3+
usingSystem.IO;
4+
usingSystem.Linq;
5+
usingSystem.Text;
6+
7+
usingMicrosoft.Build.Framework;
8+
usingMicrosoft.Build.Utilities;
9+
10+
usingNUnit.Framework;
11+
12+
usingXamarin.Utils;
13+
14+
namespaceXamarin.MacDev.Tasks{
15+
[TestFixture]
16+
publicclassCollectBundleResourcesTaskTests:TestBase{
17+
[Test]
18+
publicvoidLogicalNameOutsideAppBundle()
19+
{
20+
varcurrentDirectory=Environment.CurrentDirectory;
21+
try{
22+
vartmpdir=Cache.CreateTemporaryDirectory();
23+
vartask=CreateTask<CollectBundleResources>();
24+
varitem=newTaskItem("image.png");
25+
varprojDir=Path.Combine(tmpdir,"B");
26+
Directory.CreateDirectory(projDir);
27+
Environment.CurrentDirectory=projDir;
28+
File.WriteAllText(Path.Combine(projDir,item.ItemSpec),"image!");
29+
item.SetMetadata("LocalDefiningProjectFullPath",Path.Combine(tmpdir,"A","SDK.csproj"));
30+
item.SetMetadata("LocalMSBuildProjectFullPath",Path.Combine(projDir,"Project.csproj"));
31+
task.BundleResources=[item];
32+
varrv=task.Execute();
33+
34+
Assert.That(Engine.Logger.ErrorEvents.Count,Is.EqualTo(0),"Errors");
35+
36+
Assert.That(Engine.Logger.WarningsEvents.Count,Is.EqualTo(1),"Warnings");
37+
Assert.That(Engine.Logger.WarningsEvents[0].Message,Is.EqualTo("The path '../B/image.png' would result in a file outside of the app bundle and cannot be used."),"Warning Message");
38+
39+
Assert.That(rv,Is.True,"Execute");
40+
}finally{
41+
Environment.CurrentDirectory=currentDirectory;
42+
}
43+
}
44+
}
45+
}

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp