Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ArgumentParser<_>.PrintCommandLineArgumentsFlat does not escape '\n' #136

Open
kleidemos opened this issue Sep 8, 2019 · 5 comments
Open

Comments

@kleidemos
Copy link
Contributor

Repro steps

module BugInArgu =
  open Expecto
  open Expecto.Flip
  open Argu

  type Args =
    | SomeString of string

    interface IArgParserTemplate with
      member this.Usage =
        match this with
        | SomeString _ -> "NIE"

  let parser =
    ArgumentParser<Args>()

  [<Tests>]
  let tests =
    ftestList "argu" [
      testCase "string contains new line" <| fun () ->
        let str = "\nnewLine\nnewLine\n"
        let args = [
          SomeString str
        ]
        
        args
        |> parser.PrintCommandLineArgumentsFlat
        |> Expect.equal "" (sprintf "--somestring %A" str)
    ]

Actual behavior

[23:40:21 ERR] argu/string contains new line failed in 00:00:00.0420000.
. String does not match at position 13. Expected char: '"', but got '\010'.
expected:
--somestring "
newLine
newLine
"
  actual:
--somestring
newLine
newLine

   at...
@kleidemos kleidemos changed the title ArgumentParser<_>.PrintCommandLineArgumentsFlat does not escape '\n' ArgumentParser<_>.PrintCommandLineArgumentsFlat does not escape '\n' Sep 8, 2019
@eiriktsarpalis
Copy link
Member

eiriktsarpalis commented Sep 16, 2019

I'm not sure I understand what the expected behaviour is. The method prints literal quotes but fails to do so if you add newline chars?

@kleidemos
Copy link
Contributor Author

PrintCommandLineArgumentsFlat must quote parameters with newline chars, like whitespaces.

@eiriktsarpalis
Copy link
Member

PrintCommandLineArgumentsFlat must quote parameters with newline chars, like whitespaces.

Could you elaborate why? Why shouldn't it be quoted if that is not the case?

@kleidemos
Copy link
Contributor Author

Sorry. But I didn't understand or couldn't translate the question.

  • Using %A generates the required string only in this case. I was too lazy to write full implementation.
  • We can quote any string, even if it is not necessary. But it doesn't seem good.

@bartelink
Copy link
Member

@kleidemos Would you be able to provide a PR? Eirik is no longer maintaining this as of #191

Realistically the fact that this API is not a mainstream thing means resolving this won't get to the top of the up for grabs or good-first-issue lists in any reasonable length of time (I'm trying to make this issues list tractable, as no issue will ever get resolved if its just a dumping ground)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants