Giter Club home page Giter Club logo

Comments (11)

StefH avatar StefH commented on June 2, 2024 1

#788

from system.linq.dynamic.core.

brettwinters avatar brettwinters commented on June 2, 2024 1

ok, got it.

When I run these tests using 1.3.10:

[Theory]
[InlineData("\"{\\\"PropertyA\\\":\\\"abc\\\"}\"", "{\"PropertyA\":\"abc\"}")]
[InlineData("\"{\\\"PropertyA\\\":\\\" \\\"}\"", "{\"PropertyA\":\" \"}")]
[InlineData("\"{\\\"PropertyA\\\":\\\"\\\"}\"", "{\"PropertyA\":\"\"}")]
[InlineData("\"{\\\\\\\"PropertyA\\\\\\\":\\\\\\\"\\\\\\\"}\"", "{\\\"PropertyA\\\":\\\"\\\"}")]
public void GivenJsonString_WhenParseLambda_ThenShouldOutputEscapedJson(
	string jsonString,
	string expectedResult)
{
	var actualResult = DynamicExpressionParser
		.ParseLambda(typeof(object), jsonString)
		.Compile()
		.DynamicInvoke();
	
	Assert.Equal(
		expectedResult,
		actualResult?.ToString()
	);
}

They fail as originally described:
image

Then when I run the same tests using 1.3.11-preview-01

image

All pass!

Thank you very much for your quick fix, I'll look out for 1.3.11

from system.linq.dynamic.core.

brettwinters avatar brettwinters commented on June 2, 2024

#163 #307

from system.linq.dynamic.core.

brettwinters avatar brettwinters commented on June 2, 2024

BTW I'm using System.Linq.Dynamic.Core v1.3.10

from system.linq.dynamic.core.

StefH avatar StefH commented on June 2, 2024

@brettwinters
Can you please test preview version 1.3.11-preview-01?

From: https://www.myget.org/F/system-linq-dynamic-core/api/v3/index.json

from system.linq.dynamic.core.

brettwinters avatar brettwinters commented on June 2, 2024

Hi @StefH - I'm having some trouble using myget. Sorry about this but would you mind publishing to nuget? otherwise please could you point me to a online c# ide so I can write some tests?

from system.linq.dynamic.core.

StefH avatar StefH commented on June 2, 2024

This page describes how to use myget:
https://github.com/WireMock-Net/WireMock.Net/wiki/MyGet-preview-versions

from system.linq.dynamic.core.

StefH avatar StefH commented on June 2, 2024

@brettwinters
Some advice is needed.

I did introduce a new config enum like below to make sure that this solution is now the default, but if users want to use the old parsing, they can configure it.

Do you think it's a good naming?

namespace System.Linq.Dynamic.Core.Config;

/// <summary>
/// Defines the types of string literal parsing that can be performed.
/// </summary>
public enum StringLiteralParsingType : byte
{
    /// <summary>
    /// Represents the default string literal parsing type. Double quotes should be escaped using the default escaping.
    /// E.G. var expression = "StaticHelper.Filter(\"UserName == \\\"x\\\"\")";
    /// 
    /// [Default]
    /// </summary>
    Default = 0,

    /// <summary>
    /// Represents a string literal parsing type where a double quotes should be escaped by two double quotes.
    /// E.G. var expression = "StaticHelper.Filter(\"UserName == "\"\"x\"\"\")";
    /// </summary>
    EscapeDoubleQuoteByTwoDoubleQuotes = 1
}

from system.linq.dynamic.core.

brettwinters avatar brettwinters commented on June 2, 2024

Hi @StefH - escaping and unescaping serialised strings get really confusing quickly haha

The rule I think is that each pair of backslashes \\ turns into a single backslash \ and \" turns into " right? so combining, like this \\\" turns into \" (i.e. " when deserialised again into memory).

So \"UserName == \\\"x\\\"\" -> "UserName == \"x\"" (i.e. UserName == "x" in memory)

But the EscapeDoubleQuoteByTwoDoubleQuotes \"UserName == "\"\"x\"\"\" -> "UserName == "x"" (i.e. UserName == x" in memory) which to me looks wrong so I'd call it "Legacy" with an [Obsolete] attribute but I'm not sure who depends on this behaviour...

from system.linq.dynamic.core.

brettwinters avatar brettwinters commented on June 2, 2024

wait I just confused myself. You're right \"UserName == "\"\"x\"\"\" -> UserName == "x" - it's totally correct and valid since it's another method of escaping: Escape with backslash (\" and \\) vs escape with double quotes ("" i.e. ""abc"") (so by default EscapeWithBackslash and option EscapeWithDoubleQuotes. In the second example you're using both methods. Can you combine the parser logic to handle both cases?

from system.linq.dynamic.core.

StefH avatar StefH commented on June 2, 2024

The parser cannot handle both cases automatically. You need to use the config.

(I did not notice the error in the example, I will verify it..)

from system.linq.dynamic.core.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.