Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 10 additions & 3 deletions Sdl.Web.Common/Extensions/StringExtensions.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
using System;
using System;
using System.Text.RegularExpressions;

namespace Sdl.Web.Common.Extensions
Expand All @@ -23,8 +23,10 @@ public static class StringExtensions
/// </summary>
public static bool HasNOrMoreOccurancesOfChar(this string str, int n, char c)
{
if (n <= 0) return true;
if (string.IsNullOrEmpty(str)) return false;
int count = 0;
for (int i = 0; i < str.Length || count >= n; i++)
for (int i = 0; i < str.Length && count < n; i++)
{
if (str[i] == c)
{
Expand All @@ -37,7 +39,12 @@ public static bool HasNOrMoreOccurancesOfChar(this string str, int n, char c)
/// <summary>
/// Returns a string converted to camel case.
/// </summary>
public static string ToCamelCase(this string str) => str.Substring(0, 1).ToLower() + str.Substring(1);
public static string ToCamelCase(this string str)
{
if (string.IsNullOrEmpty(str)) return str;
if (str.Length == 1) return str.ToLower();
return char.ToLower(str[0]) + str.Substring(1);
}

/// <summary>
/// Returns a new string in which all occurances of a specifid string are replaced with a new string
Expand Down
33 changes: 23 additions & 10 deletions Sdl.Web.Tridion/Mapping/StronglyTypedTopicBuilder.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
using System;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Reflection;
Expand All @@ -12,6 +12,7 @@
using Sdl.Web.Common.Mapping;
using System.Collections;
using Sdl.Web.Common.Configuration;
using System.IO;

namespace Sdl.Web.Tridion.Mapping
{
Expand Down Expand Up @@ -129,18 +130,30 @@ protected virtual XmlElement ParseXhtml(GenericTopic genericTopic)
{
using (new Tracer(genericTopic))
{
XmlDocument topicXmlDoc = new XmlDocument();
topicXmlDoc.LoadXml($"<topic>{genericTopic.TopicBody}</topic>");
XmlReaderSettings settings = new XmlReaderSettings
{
DtdProcessing = DtdProcessing.Prohibit,
XmlResolver = null
};
using (var stringReader = new StringReader($"<topic>{genericTopic.TopicBody}</topic>"))
using (var xmlReader = XmlReader.Create(stringReader, settings))
{
XmlDocument topicXmlDoc = new XmlDocument
{
XmlResolver = null
};
topicXmlDoc.Load(xmlReader);

XmlElement topicElement = topicXmlDoc.DocumentElement;
XmlElement topicElement = topicXmlDoc.DocumentElement;

// Inject GenericTopic's TopicTitle as additional HTML element
XmlElement topicTitleElement = topicXmlDoc.CreateElement("h1");
topicTitleElement.SetAttribute("class", "_topicTitle");
topicTitleElement.InnerText = genericTopic.TopicTitle;
topicElement.AppendChild(topicTitleElement);
// Inject GenericTopic's TopicTitle as additional HTML element
XmlElement topicTitleElement = topicXmlDoc.CreateElement("h1");
topicTitleElement.SetAttribute("class", "_topicTitle");
topicTitleElement.InnerText = genericTopic.TopicTitle;
topicElement.AppendChild(topicTitleElement);

return topicElement;
return topicElement;
}
}
}

Expand Down
20 changes: 10 additions & 10 deletions Sdl.Web.Tridion/Statics/BinaryFileManager.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
using System;
using System;
using System.Drawing;
using System.Drawing.Drawing2D;
using System.Drawing.Imaging;
Expand Down Expand Up @@ -319,15 +319,15 @@ internal static byte[] ResizeImage(byte[] imageData, Dimensions dimensions, Imag
grPhoto.PixelOffsetMode = PixelOffsetMode.HighQuality;
grPhoto.DrawImage(imgPhoto, new Rectangle(0, 0, targetW, targetH), cropX, cropY, sourceW, sourceH, GraphicsUnit.Pixel);
// Save out to memory and then to a file. We dispose of all objects to make sure the files don't stay locked.
using (MemoryStream memoryStream = new MemoryStream())
{
bmPhoto.Save(memoryStream, imageFormat);
original.Dispose();
imgPhoto.Dispose();
bmPhoto.Dispose();
grPhoto.Dispose();
return memoryStream.GetBuffer();
}
using (MemoryStream memoryStream = new MemoryStream())
{
bmPhoto.Save(memoryStream, imageFormat);
original.Dispose();
imgPhoto.Dispose();
bmPhoto.Dispose();
grPhoto.Dispose();
return memoryStream.ToArray();
}
}
}

Expand Down
Loading