mirror of
https://github.com/OrchardCMS/Orchard.git
synced 2025-07-16 19:41:16 +08:00
#20078: Fixing international characters loss in media profiles
Work Item: 20078
This commit is contained in:
parent
a41bd67800
commit
8ef54ff18f
@ -1,54 +1,46 @@
|
|||||||
using System;
|
using Moq;
|
||||||
using System.Collections.Generic;
|
|
||||||
using System.Linq;
|
|
||||||
using System.Text;
|
|
||||||
using Moq;
|
|
||||||
using NUnit.Framework;
|
using NUnit.Framework;
|
||||||
using Orchard.Autoroute.Services;
|
using Orchard.Autoroute.Services;
|
||||||
|
|
||||||
namespace Orchard.Tests.Modules.Autoroute {
|
namespace Orchard.Tests.Modules.Autoroute {
|
||||||
[TestFixture]
|
[TestFixture]
|
||||||
public class DefaultSlugServiceTests {
|
public class DefaultSlugServiceTests {
|
||||||
|
|
||||||
|
private DefaultSlugService _slugService = new DefaultSlugService(new Mock<ISlugEventHandler>().Object);
|
||||||
|
|
||||||
[Test]
|
[Test]
|
||||||
public void ShouldStripContiguousDashes() {
|
public void ShouldStripContiguousDashes() {
|
||||||
DefaultSlugService slugService = new DefaultSlugService(new Mock<ISlugEventHandler>().Object);
|
Assert.That(_slugService.Slugify("a - b"), Is.EqualTo("a-b"));
|
||||||
|
|
||||||
Assert.That(slugService.Slugify("a - b"), Is.EqualTo("a-b"));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
[Test]
|
[Test]
|
||||||
public void ShouldStripContiguousDashes2() {
|
public void ShouldStripContiguousDashes2() {
|
||||||
DefaultSlugService slugService = new DefaultSlugService(new Mock<ISlugEventHandler>().Object);
|
Assert.That(_slugService.Slugify("a - - - - - -b"), Is.EqualTo("a-b"));
|
||||||
|
|
||||||
Assert.That(slugService.Slugify("a - - - - - -b"), Is.EqualTo("a-b"));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
[Test]
|
[Test]
|
||||||
public void ShouldStripContiguousDashesEverywhere() {
|
public void ShouldStripContiguousDashesEverywhere() {
|
||||||
DefaultSlugService slugService = new DefaultSlugService(new Mock<ISlugEventHandler>().Object);
|
Assert.That(_slugService.Slugify("a - b - c -- d"), Is.EqualTo("a-b-c-d"));
|
||||||
|
|
||||||
Assert.That(slugService.Slugify("a - b - c -- d"), Is.EqualTo("a-b-c-d"));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
[Test]
|
[Test]
|
||||||
public void ShouldChangePercentSymbolsToHyphans() {
|
public void ShouldChangePercentSymbolsToHyphans() {
|
||||||
DefaultSlugService slugService = new DefaultSlugService(new Mock<ISlugEventHandler>().Object);
|
Assert.That(_slugService.Slugify("a%d"), Is.EqualTo("a-d"));
|
||||||
|
|
||||||
Assert.That(slugService.Slugify("a%d"), Is.EqualTo("a-d"));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
[Test]
|
[Test]
|
||||||
public void ShouldChangeDotSymbolsToHyphans() {
|
public void ShouldChangeDotSymbolsToHyphans() {
|
||||||
DefaultSlugService slugService = new DefaultSlugService(new Mock<ISlugEventHandler>().Object);
|
Assert.That(_slugService.Slugify("a,d"), Is.EqualTo("a-d"));
|
||||||
|
|
||||||
Assert.That(slugService.Slugify("a,d"), Is.EqualTo("a-d"));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
[Test]
|
[Test]
|
||||||
public void ShouldMakeSureFunkycharactersAndHyphansOnlyReturnSingleHyphan() {
|
public void ShouldMakeSureFunkycharactersAndHyphansOnlyReturnSingleHyphan() {
|
||||||
DefaultSlugService slugService = new DefaultSlugService(new Mock<ISlugEventHandler>().Object);
|
Assert.That(_slugService.Slugify("a-%-.d"), Is.EqualTo("a-d"));
|
||||||
|
}
|
||||||
|
|
||||||
Assert.That(slugService.Slugify("a-%-.d"), Is.EqualTo("a-d"));
|
[Test]
|
||||||
|
public void ShouldPreserveCyrilicCharacters() {
|
||||||
|
Assert.That(_slugService.Slugify("джинсы_клеш"), Is.EqualTo("джинсы_клеш"));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -0,0 +1,28 @@
|
|||||||
|
using System.Reflection;
|
||||||
|
using Moq;
|
||||||
|
using NUnit.Framework;
|
||||||
|
using Orchard.MediaProcessing.Services;
|
||||||
|
|
||||||
|
namespace Orchard.Tests.Modules.ImageProcessing {
|
||||||
|
[TestFixture]
|
||||||
|
public class ImageProcessingTests {
|
||||||
|
|
||||||
|
private readonly MethodInfo _createDefaultFilename = typeof(ImageProfileManager).GetMethod("CreateDefaultFileName", BindingFlags.NonPublic | BindingFlags.Static);
|
||||||
|
|
||||||
|
private string CreateDefaultFileName(string path) {
|
||||||
|
return (string)_createDefaultFilename.Invoke(null, new object[] {path});
|
||||||
|
}
|
||||||
|
|
||||||
|
[Test]
|
||||||
|
public void CreateDefaultFilenameRemovesInvalidChars() {
|
||||||
|
Assert.That(CreateDefaultFileName("abcdef"), Is.EqualTo("abcdef"));
|
||||||
|
Assert.That(CreateDefaultFileName("abc_def"), Is.EqualTo("abc_def"));
|
||||||
|
}
|
||||||
|
|
||||||
|
[Test]
|
||||||
|
public void CreateDefaultFilenamePeservesInternationalLetters() {
|
||||||
|
Assert.That(CreateDefaultFileName("aéçâê"), Is.EqualTo("aecae"));
|
||||||
|
Assert.That(CreateDefaultFileName("джинсы_клеш"), Is.EqualTo("джинсы_клеш"));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -141,6 +141,7 @@
|
|||||||
<Compile Include="CodeGeneration\Commands\CodeGenerationCommandsTests.cs" />
|
<Compile Include="CodeGeneration\Commands\CodeGenerationCommandsTests.cs" />
|
||||||
<Compile Include="Comments\Services\CommentServiceTests.cs" />
|
<Compile Include="Comments\Services\CommentServiceTests.cs" />
|
||||||
<Compile Include="Email\EmailChannelTests.cs" />
|
<Compile Include="Email\EmailChannelTests.cs" />
|
||||||
|
<Compile Include="ImageProcessing\ImageProcessingTests.cs" />
|
||||||
<Compile Include="ImportExport\Services\ImportExportServiceTests.cs" />
|
<Compile Include="ImportExport\Services\ImportExportServiceTests.cs" />
|
||||||
<Compile Include="Indexing\IndexingTaskExecutorTests.cs" />
|
<Compile Include="Indexing\IndexingTaskExecutorTests.cs" />
|
||||||
<Compile Include="Indexing\LuceneIndexProviderTests.cs" />
|
<Compile Include="Indexing\LuceneIndexProviderTests.cs" />
|
||||||
@ -218,6 +219,10 @@
|
|||||||
<Project>{EA2B9121-EF54-40A6-A53E-6593C86EE696}</Project>
|
<Project>{EA2B9121-EF54-40A6-A53E-6593C86EE696}</Project>
|
||||||
<Name>Orchard.Indexing</Name>
|
<Name>Orchard.Indexing</Name>
|
||||||
</ProjectReference>
|
</ProjectReference>
|
||||||
|
<ProjectReference Include="..\Orchard.Web\Modules\Orchard.MediaProcessing\Orchard.MediaProcessing.csproj">
|
||||||
|
<Project>{08191FCD-7258-4F19-95FB-AEC3DE77B2EB}</Project>
|
||||||
|
<Name>Orchard.MediaProcessing</Name>
|
||||||
|
</ProjectReference>
|
||||||
<ProjectReference Include="..\Orchard.Web\Modules\Orchard.Media\Orchard.Media.csproj">
|
<ProjectReference Include="..\Orchard.Web\Modules\Orchard.Media\Orchard.Media.csproj">
|
||||||
<Project>{D9A7B330-CD22-4DA1-A95A-8DE1982AD8EB}</Project>
|
<Project>{D9A7B330-CD22-4DA1-A95A-8DE1982AD8EB}</Project>
|
||||||
<Name>Orchard.Media</Name>
|
<Name>Orchard.Media</Name>
|
||||||
|
@ -197,11 +197,20 @@ namespace Orchard.MediaProcessing.Services {
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private static readonly char[] _disallowed = @"/:?#\[\]@!$&'()*+,.;=\s\""\<\>\\\|%".ToCharArray();
|
||||||
|
|
||||||
private static string CreateDefaultFileName(string path) {
|
private static string CreateDefaultFileName(string path) {
|
||||||
var extention = Path.GetExtension(path);
|
var extention = Path.GetExtension(path);
|
||||||
var newPath = Path.ChangeExtension(path, "");
|
var newPath = Path.ChangeExtension(path, "");
|
||||||
newPath = newPath.Replace(@"/", "_");
|
newPath = newPath.TrimEnd('.').RemoveDiacritics();
|
||||||
return newPath.ToSafeName() + extention;
|
var normalized = newPath.ToCharArray();
|
||||||
|
for (var i = 0; i < normalized.Length; i++) {
|
||||||
|
if (Array.IndexOf(_disallowed, normalized[i]) >= 0) {
|
||||||
|
normalized[i] = '_';
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return new string(normalized) + extention;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -196,7 +196,7 @@ namespace Orchard.Utility.Extensions {
|
|||||||
return (c == '\r' || c == '\n' || c == '\t' || c == '\f' || c == ' ');
|
return (c == '\r' || c == '\n' || c == '\t' || c == '\f' || c == ' ');
|
||||||
}
|
}
|
||||||
|
|
||||||
public static string RemoveDiacritics(string name) {
|
public static string RemoveDiacritics(this string name) {
|
||||||
string stFormD = name.Normalize(NormalizationForm.FormD);
|
string stFormD = name.Normalize(NormalizationForm.FormD);
|
||||||
var sb = new StringBuilder();
|
var sb = new StringBuilder();
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user