Merge pull request #1355 from umbraco/temp-U4-8561

Properly URL Encodes stylesheet properties
This commit is contained in:
Warren Buckley
2016-07-07 10:47:48 +01:00
committed by GitHub
3 changed files with 16 additions and 33 deletions

View File

@@ -58,12 +58,12 @@ namespace umbraco
{
var sheetId = sheet.Path.TrimEnd(".css");
var xNode = XmlTreeNode.Create(this);
xNode.NodeID = sheetId + "_" + prop.Name;
xNode.NodeID = sheetId + "_" + HttpUtility.UrlEncode(prop.Name);
xNode.Text = prop.Name;
xNode.Action = "javascript:openStylesheetProperty('" +
//Needs to be escaped for JS
HttpUtility.UrlEncode(sheet.Path) +
"','" + prop.Name + "');";
"','" + HttpUtility.UrlEncode(prop.Name) + "');";
xNode.Icon = "icon-brackets";
xNode.OpenIcon = "icon-brackets";

View File

@@ -1,32 +1,25 @@
using System;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Windows.Forms;
using Umbraco.Core;
using Umbraco.Core.Models;
using Umbraco.Web.UI;
using umbraco.BusinessLogic;
using umbraco.DataLayer;
using umbraco.BasePages;
using Umbraco.Core.IO;
using umbraco.cms.businesslogic.member;
namespace umbraco
{
public class stylesheetPropertyTasks : LegacyDialogTask
{
public override bool PerformSave()
{
var stylesheetName = AdditionalValues["nodeId"].ToString();
var s = Umbraco.Core.ApplicationContext.Current.Services.FileService.GetStylesheetByName(stylesheetName.EnsureEndsWith(".css"));
var s = ApplicationContext.Current.Services.FileService.GetStylesheetByName(stylesheetName.EnsureEndsWith(".css"));
s.AddProperty(new StylesheetProperty(Alias, "." + Alias.ToSafeAlias(), ""));
Umbraco.Core.ApplicationContext.Current.Services.FileService.SaveStylesheet(s);
ApplicationContext.Current.Services.FileService.SaveStylesheet(s);
_returnUrl = string.Format("settings/stylesheet/property/EditStyleSheetProperty.aspx?id={0}&prop={1}", HttpUtility.UrlEncode(s.Path), Alias);
// SJ - Note: The Alias is NOT in fact the alias but the name of the new property, need to UrlEncode it!
_returnUrl = string.Format("settings/stylesheet/property/EditStyleSheetProperty.aspx?id={0}&prop={1}", HttpUtility.UrlEncode(s.Path), HttpUtility.UrlEncode(Alias));
return true;
}
@@ -34,15 +27,16 @@ namespace umbraco
{
var parts = Alias.Split('_');
var stylesheet = Umbraco.Core.ApplicationContext.Current.Services.FileService.GetStylesheetByName(parts[0].EnsureEndsWith(".css"));
var stylesheet = ApplicationContext.Current.Services.FileService.GetStylesheetByName(parts[0].EnsureEndsWith(".css"));
if (stylesheet == null) throw new InvalidOperationException("No stylesheet found by name: " + parts[0]);
var prop = stylesheet.Properties.FirstOrDefault(x => x.Name == parts[1]);
if (prop == null) throw new InvalidOperationException("No stylesheet property found by name: " + parts[1]);
var property = HttpUtility.UrlDecode(parts[1]);
var prop = stylesheet.Properties.FirstOrDefault(x => x.Name == property);
if (prop == null) throw new InvalidOperationException("No stylesheet property found by name: " + property);
stylesheet.RemoveProperty(prop.Name);
Umbraco.Core.ApplicationContext.Current.Services.FileService.SaveStylesheet(stylesheet);
ApplicationContext.Current.Services.FileService.SaveStylesheet(stylesheet);
return true;
}

View File

@@ -1,19 +1,7 @@
using System;
using System.Collections;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Web;
using System.Web.Services.Description;
using System.Web.SessionState;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.HtmlControls;
using umbraco.cms.businesslogic.web;
using Umbraco.Core;
using Umbraco.Web;
using umbraco.cms.presentation.Trees;
using Umbraco.Core;
namespace umbraco.cms.presentation.settings.stylesheet
@@ -43,10 +31,11 @@ namespace umbraco.cms.presentation.settings.stylesheet
_sheet = Services.FileService.GetStylesheetByName(Request.QueryString["id"]);
if (_sheet == null) throw new InvalidOperationException("No stylesheet found with name: " + Request.QueryString["id"]);
var propName = IsPostBack ? OriginalName.Value : Request.QueryString["prop"];
var property = HttpUtility.UrlDecode(Request.QueryString["prop"]);
var propName = IsPostBack ? OriginalName.Value : property;
_stylesheetproperty = _sheet.Properties.FirstOrDefault(x => x.Name.InvariantEquals(propName));
if (_stylesheetproperty == null) throw new InvalidOperationException("No stylesheet property found with name: " + Request.QueryString["prop"]);
if (_stylesheetproperty == null) throw new InvalidOperationException("No stylesheet property found with name: " + property);
Panel1.Text = ui.Text("stylesheet", "editstylesheetproperty", UmbracoUser);
@@ -70,7 +59,7 @@ namespace umbraco.cms.presentation.settings.stylesheet
var nodePath = string.Format("-1,init,{0},{0}_{1}", _sheet.Path
//needs a double escape to work with JS
.Replace("\\", "\\\\").TrimEnd(".css"), _stylesheetproperty.Name);
.Replace("\\", "\\\\").TrimEnd(".css"), HttpUtility.UrlEncode(_stylesheetproperty.Name));
ClientTools
.SetActiveTreeType(Constants.Trees.Stylesheets)