Skip to content

Commit

Permalink
Fix escaping of the path
Browse files Browse the repository at this point in the history
  • Loading branch information
kant2002 authored and ForNeVeR committed Jan 15, 2024
1 parent b9dd759 commit a8120fc
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 3 deletions.
11 changes: 9 additions & 2 deletions Cesium.Parser.Tests/PreprocessorTests/PreprocessorTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,11 @@ private static async Task DoTest(string source, Dictionary<string, string>? stan

private static async Task<string> DoPreprocess(string source, Dictionary<string, string>? standardHeaders = null, Dictionary<string, IList<IToken<CPreprocessorTokenType>>>? defines = null)
{
var lexer = new CPreprocessorLexer(source);
var filePath = "c:\\a\\b\\c.c";
var lexer = new CPreprocessorLexer(filePath, source);
var includeContext = new IncludeContextMock(standardHeaders ?? new Dictionary<string, string>());
var definesContext = new InMemoryDefinesContext(defines ?? new Dictionary<string, IList<IToken<CPreprocessorTokenType>>>());
var preprocessor = new CPreprocessor(source, lexer, includeContext, definesContext);
var preprocessor = new CPreprocessor(filePath, lexer, includeContext, definesContext);
var result = await preprocessor.ProcessSource();
return result;
}
Expand Down Expand Up @@ -432,5 +433,11 @@ public Task DoubleHashOperator() => DoTest(
public Task LineDefine() => DoTest(
@"
int x = __LINE__;
");

[Fact]
public Task FileDefine() => DoTest(
@"
char* x = __FILE__;
");
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@

char* x = "c:\\a\\b\\c.c";
2 changes: 1 addition & 1 deletion Cesium.Preprocessor/CPreprocessor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -248,7 +248,7 @@ private IEnumerable<IToken<CPreprocessorTokenType>> ReplaceMacro(IToken<CPreproc
{
if (objectMacro.Name == "__FILE__")
{
yield return new Token<CPreprocessorTokenType>(token.Range, token.Location, "\"" + token.Location.File?.Path + "\"", PreprocessingToken);
yield return new Token<CPreprocessorTokenType>(token.Range, token.Location, "\"" + token.Location.File?.Path.Replace("\\", "\\\\") + "\"", PreprocessingToken);
yield break;
}

Expand Down

0 comments on commit a8120fc

Please sign in to comment.