#17820: Extension descriptor parser keyword comparisons should be case insensitive.

--HG--
branch : 1.x
This commit is contained in:
Andre Rodrigues
2011-05-14 17:34:13 -07:00
parent 744ddf1c61
commit 5d31f5b8d9
3 changed files with 95 additions and 60 deletions

View File

@@ -138,6 +138,22 @@ namespace Orchard.Tests.Environment.Extensions {
Assert.That(available, Has.Some.Property("Id").EqualTo("foo"));
}
[Test]
public void ExtensionDescriptorKeywordsAreCaseInsensitive() {
_folders.Manifests.Add("Sample", @"
NaMe: Sample Extension
version: 2.x
DESCRIPTION: HELLO
");
var descriptor = _manager.AvailableExtensions().Single();
Assert.That(descriptor.Id, Is.EqualTo("Sample"));
Assert.That(descriptor.Name, Is.EqualTo("Sample Extension"));
Assert.That(descriptor.Version, Is.EqualTo("2.x"));
Assert.That(descriptor.Description, Is.EqualTo("HELLO"));
}
[Test]
public void ExtensionDescriptorsShouldHaveNameAndVersion() {

View File

@@ -41,8 +41,8 @@ namespace Orchard.Packaging.Services {
IEnumerable<IPackage> repositoryPackages = SourceRepository.GetPackages().ToList();
IEnumerable<IPackage> packages = from extension in _extensionManager.AvailableExtensions()
let id = PackageBuilder.BuildPackageId(extension.Id, extension.ExtensionType)
let version = Version.Parse(extension.Version)
let package = repositoryPackages.FirstOrDefault(p => p.Id == id && p.Version == version)
let version = extension.Version != null ? Version.Parse(extension.Version) : null
let package = repositoryPackages.FirstOrDefault(p => p.Id == id && (version == null || p.Version == version))
where package != null
select package;

View File

@@ -11,6 +11,24 @@ using Orchard.Utility.Extensions;
namespace Orchard.Environment.Extensions.Folders {
public class ExtensionFolders : IExtensionFolders {
private const string NameSection = "name";
private const string PathSection = "path";
private const string DescriptionSection = "description";
private const string VersionSection = "version";
private const string OrchardVersionSection = "orchardversion";
private const string AuthorSection = "author";
private const string WebsiteSection = "website";
private const string TagsSection = "tags";
private const string AntiForgerySection = "antiforgery";
private const string ZonesSection = "zones";
private const string BaseThemeSection = "basetheme";
private const string DependenciesSection = "dependencies";
private const string CategorySection = "category";
private const string FeatureDescriptionSection = "featuredescription";
private const string FeatureNameSection = "featurename";
private const string PrioritySection = "priority";
private const string FeaturesSection = "features";
private readonly IEnumerable<string> _paths;
private readonly string _manifestName;
private readonly string _extensionType;
@@ -89,17 +107,17 @@ namespace Orchard.Environment.Extensions.Folders {
Location = locationPath,
Id = extensionId,
ExtensionType = extensionType,
Name = GetValue(manifest, "Name") ?? extensionId,
Path = GetValue(manifest, "Path"),
Description = GetValue(manifest, "Description"),
Version = GetValue(manifest, "Version"),
OrchardVersion = GetValue(manifest, "OrchardVersion"),
Author = GetValue(manifest, "Author"),
WebSite = GetValue(manifest, "Website"),
Tags = GetValue(manifest, "Tags"),
AntiForgery = GetValue(manifest, "AntiForgery"),
Zones = GetValue(manifest, "Zones"),
BaseTheme = GetValue(manifest, "BaseTheme"),
Name = GetValue(manifest, NameSection) ?? extensionId,
Path = GetValue(manifest, PathSection),
Description = GetValue(manifest, DescriptionSection),
Version = GetValue(manifest, VersionSection),
OrchardVersion = GetValue(manifest, OrchardVersionSection),
Author = GetValue(manifest, AuthorSection),
WebSite = GetValue(manifest, WebsiteSection),
Tags = GetValue(manifest, TagsSection),
AntiForgery = GetValue(manifest, AntiForgerySection),
Zones = GetValue(manifest, ZonesSection),
BaseTheme = GetValue(manifest, BaseThemeSection)
};
extensionDescriptor.Features = GetFeaturesForExtension(manifest, extensionDescriptor);
@@ -140,57 +158,57 @@ namespace Orchard.Environment.Extensions.Folders {
for (int i = 0; i < fieldLength; i++) {
field[i] = field[i].Trim();
}
switch (field[0]) {
case "Name":
manifest.Add("Name", field[1]);
switch (field[0].ToLowerInvariant()) {
case NameSection:
manifest.Add(NameSection, field[1]);
break;
case "Path":
manifest.Add("Path", field[1]);
case PathSection:
manifest.Add(PathSection, field[1]);
break;
case "Description":
manifest.Add("Description", field[1]);
case DescriptionSection:
manifest.Add(DescriptionSection, field[1]);
break;
case "Version":
manifest.Add("Version", field[1]);
case VersionSection:
manifest.Add(VersionSection, field[1]);
break;
case "OrchardVersion":
manifest.Add("OrchardVersion", field[1]);
case OrchardVersionSection:
manifest.Add(OrchardVersionSection, field[1]);
break;
case "Author":
manifest.Add("Author", field[1]);
case AuthorSection:
manifest.Add(AuthorSection, field[1]);
break;
case "Website":
manifest.Add("Website", field[1]);
case WebsiteSection:
manifest.Add(WebsiteSection, field[1]);
break;
case "Tags":
manifest.Add("Tags", field[1]);
case TagsSection:
manifest.Add(TagsSection, field[1]);
break;
case "AntiForgery":
manifest.Add("AntiForgery", field[1]);
case AntiForgerySection:
manifest.Add(AntiForgerySection, field[1]);
break;
case "Zones":
manifest.Add("Zones", field[1]);
case ZonesSection:
manifest.Add(ZonesSection, field[1]);
break;
case "BaseTheme":
manifest.Add("BaseTheme", field[1]);
case BaseThemeSection:
manifest.Add(BaseThemeSection, field[1]);
break;
case "Dependencies":
manifest.Add("Dependencies", field[1]);
case DependenciesSection:
manifest.Add(DependenciesSection, field[1]);
break;
case "Category":
manifest.Add("Category", field[1]);
case CategorySection:
manifest.Add(CategorySection, field[1]);
break;
case "FeatureDescription":
manifest.Add("FeatureDescription", field[1]);
case FeatureDescriptionSection:
manifest.Add(FeatureDescriptionSection, field[1]);
break;
case "FeatureName":
manifest.Add("FeatureName", field[1]);
case FeatureNameSection:
manifest.Add(FeatureNameSection, field[1]);
break;
case "Priority":
manifest.Add("Priority", field[1]);
case PrioritySection:
manifest.Add(PrioritySection, field[1]);
break;
case "Features":
manifest.Add("Features", reader.ReadToEnd());
case FeaturesSection:
manifest.Add(FeaturesSection, reader.ReadToEnd());
break;
}
}
@@ -205,18 +223,18 @@ namespace Orchard.Environment.Extensions.Folders {
// Default feature
FeatureDescriptor defaultFeature = new FeatureDescriptor {
Id = extensionDescriptor.Id,
Name = GetValue(manifest, "FeatureName") ?? extensionDescriptor.Name,
Priority = GetValue(manifest, "Priority") != null ? int.Parse(GetValue(manifest, "Priority")) : 0,
Description = GetValue(manifest, "FeatureDescription") ?? GetValue(manifest, "Description") ?? string.Empty,
Dependencies = ParseFeatureDependenciesEntry(GetValue(manifest, "Dependencies")),
Name = GetValue(manifest, FeatureNameSection) ?? extensionDescriptor.Name,
Priority = GetValue(manifest, PrioritySection) != null ? int.Parse(GetValue(manifest, PrioritySection)) : 0,
Description = GetValue(manifest, FeatureDescriptionSection) ?? GetValue(manifest, DescriptionSection) ?? string.Empty,
Dependencies = ParseFeatureDependenciesEntry(GetValue(manifest, DependenciesSection)),
Extension = extensionDescriptor,
Category = GetValue(manifest, "Category")
Category = GetValue(manifest, CategorySection)
};
featureDescriptors.Add(defaultFeature);
// Remaining features
string featuresText = GetValue(manifest, "Features");
string featuresText = GetValue(manifest, FeaturesSection);
if (featuresText != null) {
FeatureDescriptor featureDescriptor = null;
using (StringReader reader = new StringReader(featuresText)) {
@@ -253,20 +271,21 @@ namespace Orchard.Environment.Extensions.Folders {
for (int i = 0; i < featureFieldLength; i++) {
featureField[i] = featureField[i].Trim();
}
switch (featureField[0]) {
case "Name":
switch (featureField[0].ToLowerInvariant()) {
case NameSection:
featureDescriptor.Name = featureField[1];
break;
case "Description":
case DescriptionSection:
featureDescriptor.Description = featureField[1];
break;
case "Category":
case CategorySection:
featureDescriptor.Category = featureField[1];
break;
case "Priority":
case PrioritySection:
featureDescriptor.Priority = int.Parse(featureField[1]);
break;
case "Dependencies":
case DependenciesSection:
featureDescriptor.Dependencies = ParseFeatureDependenciesEntry(featureField[1]);
break;
}