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

17.3.0 introduces a regression for handling quoted string #2091

Closed
jy95 opened this issue Dec 12, 2021 · 6 comments
Closed

17.3.0 introduces a regression for handling quoted string #2091

jy95 opened this issue Dec 12, 2021 · 6 comments
Labels

Comments

@jy95
Copy link

jy95 commented Dec 12, 2021

Hello,

When upgrading my dependancies to their latest versions on a branch, I detected a regression in yargs (that wasn't present in 17.2.1).

image

I created the following diff command in my project :

    diff [files..]
    
    Compare at least two i18n files & generate a report
    
    Options :
      --version             Affiche le numéro de version                   [booléen]
      --help                Affiche l'aide                                 [booléen]
      --filename, --of      Name of the output file generated by this CLI (without
                            extension)
                                  [chaîne de caractères] [défaut : (valeur générée)]
      --outputDir, --od     Output folder where to store the output file
                         [chaîne de caractères] [défaut : "D:\workspace\i18n-tools"]
      --keySeparator, --ks  Char to separate i18n keys. If working with flat JSON,
                            set this to false  [chaîne de caractères] [défaut : "."]
      --outputFormat        Output format         [choix : "JSON"] [défaut : "JSON"]
      --operations          Array of operations (such as ["ADD", "PUT"]) that should
                            be checked when comparing files
                                            [tableau] [défaut : ["DEL","ADD","PUT"]]
      --settings            Chemin du fichier de configuration JSON

When running this command on Windows in my diff.test.ts in test "JSON reporter - Inline paths should be accepted" :

diff --filename "diff_inline-JSON" --outputDir "D:\\\\TEMP\\\\TEMP" "D:\\\\TEMP\\\\TEMP\\\\tests-for-diff\\\\correct\\\\file1.json" "D:\\\\TEMP\\\\TEMP\\\\tests-for-diff\\\\correct\\\\file1.json"

I got the following stacktrace :

  console.error
    index.js diff [files..]
    
    Compare at least two i18n files & generate a report
    
    Options :
      --version             Affiche le numéro de version                   [booléen]
      --help                Affiche l'aide                                 [booléen]
      --filename, --of      Name of the output file generated by this CLI (without  
                            extension)
                                  [chaîne de caractères] [défaut : (valeur générée)]
      --outputDir, --od     Output folder where to store the output file
                         [chaîne de caractères] [défaut : "D:\workspace\i18n-tools"]
      --keySeparator, --ks  Char to separate i18n keys. If working with flat JSON,
                            set this to false  [chaîne de caractères] [défaut : "."]
      --outputFormat        Output format         [choix : "JSON"] [défaut : "JSON"]
      --operations          Array of operations (such as ["ADD", "PUT"]) that should
                            be checked when comparing files
                                            [tableau] [défaut : ["DEL","ADD","PUT"]]
      --settings            Chemin du fichier de configuration JSON

      at error (node_modules/yargs/build/index.cjs:1:43554)
      at Object.showHelp (node_modules/yargs/build/index.cjs:1:19441)
      at Jt.showHelp (node_modules/yargs/build/index.cjs:1:40813)
      at Object.fail (node_modules/yargs/build/index.cjs:1:13247)
      at node_modules/yargs/build/index.cjs:1:9269

  console.error
    undefined

      at Object.error (node_modules/yargs/build/index.cjs:1:43554)
      at Object.fail (node_modules/yargs/build/index.cjs:1:13267)
      at node_modules/yargs/build/index.cjs:1:9269

  console.error
    [Error: ENOENT: no such file or directory, open 'D:\workspace\i18n-tools\"D:\TEMP\TEMP\tests-for-diff\correct\file1.json"'] {
      errno: -4058,
      code: 'ENOENT',
      syscall: 'open',
      path: 'D:\\workspace\\i18n-tools\\"D:\\TEMP\\TEMP\\tests-for-diff\\correct\\file1.json"'
    }

      at Object.error (node_modules/yargs/build/index.cjs:1:43554)
      at Object.fail (node_modules/yargs/build/index.cjs:1:13286)
      at node_modules/yargs/build/index.cjs:1:9269

  ●  process.exit called with "1"

      at Object.exit (node_modules/yargs/build/index.cjs:1:58603)
      at Jt.exit (node_modules/yargs/build/index.cjs:1:33445)
      at Object.fail (node_modules/yargs/build/index.cjs:1:13377)
      at node_modules/yargs/build/index.cjs:1:9269

As you can see :

  • D:\workspace\i18n-tools\"D:\TEMP\TEMP\tests-for-diff\correct\file1.json seems to be a weird concatenation of two things :
  • "D:\workspace\i18n-tools" : the cwd
  • "D:\TEMP\TEMP\tests-for-diff\correct\file1.json" : the path I provided

Thanks in advance

@jly36963 jly36963 self-assigned this Dec 19, 2021
@jy95
Copy link
Author

jy95 commented Dec 27, 2021

@jly36963 I found the answer in ember-template-lint project :

There's a change in the yargs-parser dep that changes the handling of quotes inside CLI option value strings. So we have to fix our test to remove the extra quotes.

I guess it should be reported as a change at the end

@jly36963
Copy link
Contributor

jly36963 commented Dec 27, 2021

Yeah, I knew it had to do with this PR. yargs-parser had a bug where it would remove more quotes than it should (examples shown in the PR). I need to spend more time with your use case, to make sure there aren't unintended side effects to my fix.

If I understand the ember-template-lint PR correctly, this is what happened:

  • yargs-parser was removing an extra set of quotes (bug)
  • they added extra quotes to compensate for this
  • I made a PR that addressed the parser bug, which was merged and released
  • they upgraded to 17.3.0, which required them to remove the extra quotes

I'm currently working on another bug, but I'll get to this one soon.

@jy95
Copy link
Author

jy95 commented Dec 27, 2021

Sure, take your time ;)
For info, I removed some quotes in my code so that I can finally merge that PR.
To reproduce the bug on that branch, please refer to the commit with SHA 1acb97c21175e7e38bd2bbd21d028a07ddcce58a

@bcoe
Copy link
Member

bcoe commented Dec 29, 2021

@jly36963 @jy95 is there anything we need to do for this one, other than perhaps call out the behavioral change more loudly in the CHANGELOG?

@jly36963
Copy link
Contributor

@bcoe
I want to do some digging to make sure that my fix has no unintended side-effects. I'll let you know when I've finished investigating.

@jly36963 jly36963 removed their assignment Jan 29, 2023
@shadowspawn
Copy link
Member

Thanks for the detailed report. This got a good explanation, and has not had any activity in over six months.

Feel free to open a new issue if it comes up again, with new information and renewed interest.

Thank you for your contributions.

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

No branches or pull requests

4 participants