Skip to content
Open
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
12 changes: 10 additions & 2 deletions src/dotless.Core/Parser/Functions/DataUriFunction.cs
Original file line number Diff line number Diff line change
Expand Up @@ -37,18 +37,26 @@ private string GetDataUriFilename()
return filename;
}

private string ReconstructPhysicalPath(string filename)
{
if (Path.IsPathRooted(filename)) return filename;
return Path.GetFullPath(Path.Combine(Path.GetDirectoryName(Location.FileName), filename));
}

private string ConvertFileToBase64(string filename)
{
string base64;
string path = string.Empty;
try
{
base64 = Convert.ToBase64String(File.ReadAllBytes(filename));
path = ReconstructPhysicalPath(filename);
base64 = Convert.ToBase64String(File.ReadAllBytes(path));
}
catch (IOException e)
{
// this is more general than just a check to see whether the file exists
// it could fail for other reasons like security permissions
throw new ParsingException(String.Format("Data-uri function could not read file '{0}'", filename), e, Location);
throw new ParsingException(String.Format("Data-uri function could not read file '{0}' [{1}][{2}]", filename, Path.GetFullPath(filename), path), e, Location);
}
return base64;
}
Expand Down
5 changes: 5 additions & 0 deletions src/dotless.Test/SpecFixtureBase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -195,6 +195,11 @@ protected string EvaluateExpression(string expression, IDictionary<string, strin
if (string.IsNullOrEmpty(css))
return "";

return ExtractExpressionResult(css);
}

public string ExtractExpressionResult(string css)
{
var start = css.IndexOf("expression:");
var end = css.LastIndexOf(DefaultEnv().Compress ? '}' : ';');

Expand Down
Loading