Terminal adds " at the end if a folder contains \ at the end #21063

Closed
opened 2026-01-31 07:32:07 +00:00 by claunia · 10 comments
Owner

Originally created by @deadcoder0904 on GitHub (Jan 7, 2024).

Windows Terminal version

Version: 1.18.3181.0

Windows build number

Microsoft Windows [Version 10.0.22621.2861]

Other Software

deno 1.39.2 (release, x86_64-pc-windows-msvc)
v8 12.0.267.8
typescript 5.3.3

Steps to reproduce

Install deno

Paste the following script in a folder that has a subfolder.

doublequote-bug.ts

// Get folder path from Deno.args
const [folderPath] = Deno.args

// Check if folderPath is provided
if (!folderPath) {
	console.error('Please provide the folder path as an argument.')
	Deno.exit(1)
}

const root = folderPath.replace(/"/g, '') // terminal bug that adds " if foldername contains / at the end

console.log({
	folderPath,
	root,
})

Now run it using deno.

Expected Behavior

folderPath shouldn't have " at the end & it should look like root

This only happens when you have \ at the end while calling deno run.

If I remove \ manually after pressing Tab after typing how<Tab>, then both folderPath & root looks same.

PS D:\$$ Tuts> deno run .\doublequote-bug.ts '.\How to make $10k a month on Reddit'
{
  folderPath: ".\\How to make $10k a month on Reddit",
  root: ".\\How to make $10k a month on Reddit"
}

This is a source of many bugs that I faced in python as well as deno so I think it's actually a Terminal bug.

Actual Behavior

Here's what I run & the output I get:

PS D:\$$ Tuts> deno run .\doublequote-bug.ts '.\How to make $10k a month on Reddit\'
{
  folderPath: '.\\How to make $10k a month on Reddit"',
  root: ".\\How to make $10k a month on Reddit"
}

Notice the extra double quote near the end of folderPath

Originally created by @deadcoder0904 on GitHub (Jan 7, 2024). ### Windows Terminal version Version: 1.18.3181.0 ### Windows build number Microsoft Windows [Version 10.0.22621.2861] ### Other Software deno 1.39.2 (release, x86_64-pc-windows-msvc) v8 12.0.267.8 typescript 5.3.3 ### Steps to reproduce Install [deno](https://deno.com/) Paste the following script in a folder that has a subfolder. ### doublequote-bug.ts ```ts // Get folder path from Deno.args const [folderPath] = Deno.args // Check if folderPath is provided if (!folderPath) { console.error('Please provide the folder path as an argument.') Deno.exit(1) } const root = folderPath.replace(/"/g, '') // terminal bug that adds " if foldername contains / at the end console.log({ folderPath, root, }) ``` Now run it using deno. ### Expected Behavior `folderPath` shouldn't have `"` at the end & it should look like `root` This only happens when you have `\` at the end while calling `deno run`. If I remove `\` manually after pressing `Tab` after typing `how<Tab>`, then both `folderPath` & `root` looks same. ```ts PS D:\$$ Tuts> deno run .\doublequote-bug.ts '.\How to make $10k a month on Reddit' { folderPath: ".\\How to make $10k a month on Reddit", root: ".\\How to make $10k a month on Reddit" } ``` This is a source of many bugs that I faced in python as well as deno so I think it's actually a Terminal bug. ### Actual Behavior Here's what I run & the output I get: ```ts PS D:\$$ Tuts> deno run .\doublequote-bug.ts '.\How to make $10k a month on Reddit\' { folderPath: '.\\How to make $10k a month on Reddit"', root: ".\\How to make $10k a month on Reddit" } ``` Notice the extra double quote near the end of `folderPath`
claunia added the Needs-TriageIssue-BugNeeds-Repro labels 2026-01-31 07:32:07 +00:00
Author
Owner

@jamespack commented on GitHub (Jan 7, 2024):

I ran the same thing outside of deno with ts-node and it doesnt happen.

import * as  process from 'process';


// Get folder path from Deno.args
const [folderPath] = process.argv.slice(2)

// Check if folderPath is provided
if (!folderPath) {
	console.error('Please provide the folder path as an argument.')
}

const root = folderPath.replace(/"/g, '') // terminal bug that adds " if foldername contains / at the end

console.log({
	folderPath,
	root,
})


PS c:\dev\terminal-bug>ts-node .\bug.ts '.\How to make $10k a month on Reddit\'
Debugger attached.
{
  folderPath: '.\\How to make $10k a month on Reddit\\',
  root: '.\\How to make $10k a month on Reddit\\'
}

Without trailing slash:


PS c:\dev\terminal-bug>ts-node .\bug.ts '.\How to make $10k a month on Reddit'
Debugger attached.
{
  folderPath: '.\\How to make $10k a month on Reddit',
  root: '.\\How to make $10k a month on Reddit'
}
@jamespack commented on GitHub (Jan 7, 2024): I ran the same thing outside of deno with ts-node and it doesnt happen. ``` ts import * as process from 'process'; // Get folder path from Deno.args const [folderPath] = process.argv.slice(2) // Check if folderPath is provided if (!folderPath) { console.error('Please provide the folder path as an argument.') } const root = folderPath.replace(/"/g, '') // terminal bug that adds " if foldername contains / at the end console.log({ folderPath, root, }) PS c:\dev\terminal-bug>ts-node .\bug.ts '.\How to make $10k a month on Reddit\' Debugger attached. { folderPath: '.\\How to make $10k a month on Reddit\\', root: '.\\How to make $10k a month on Reddit\\' } Without trailing slash: PS c:\dev\terminal-bug>ts-node .\bug.ts '.\How to make $10k a month on Reddit' Debugger attached. { folderPath: '.\\How to make $10k a month on Reddit', root: '.\\How to make $10k a month on Reddit' } ```
Author
Owner

@DHowett commented on GitHub (Jan 8, 2024):

I ran the same thing outside of deno with ts-node and it doesnt happen.

This behavior makes it quite obvious that it's not a terminal bug. Thanks @jamespack.

@deadcoder0904 Windows Terminal does not control how arguments are passed to your process or parsed. Sorry!

@DHowett commented on GitHub (Jan 8, 2024): > I ran the same thing outside of deno with ts-node and it doesnt happen. This behavior makes it quite obvious that it's not a terminal bug. Thanks @jamespack. @deadcoder0904 Windows Terminal _does not control how arguments are passed to your process or parsed._ Sorry!
Author
Owner

@deadcoder0904 commented on GitHub (Jan 10, 2024):

@jamespack @DHowett do you mean to say it's a deno bug? because i do think i faced this in python.

i've been writing little scripts like this with python, rust, go, deno, bun with the help of chatgpt & i've tested 2-3 languages.

i'm pretty sure its a windows bug bcz mac/linux never gave me such issues few months back.

so i'm curious what this might indicate? bcz 2 languages failing at the same time should not be possible given how python has existed for so many years.

@deadcoder0904 commented on GitHub (Jan 10, 2024): @jamespack @DHowett do you mean to say it's a deno bug? because i do think i faced this in python. i've been writing little scripts like this with python, rust, go, deno, bun with the help of chatgpt & i've tested 2-3 languages. i'm pretty sure its a windows bug bcz mac/linux never gave me such issues few months back. so i'm curious what this might indicate? bcz 2 languages failing at the same time should not be possible given how python has existed for so many years.
Author
Owner

@zadjii-msft commented on GitHub (Jan 10, 2024):

If you can give us a python sample that also repros the issue, that'd be most curious for sure. But I sure haven't ever seen anything like that in my time with python 😄

Maybe there's something weird about the way PowerShell is escaping the file name, since it's got the $ in it? But I'd suspect that to be less likely

@zadjii-msft commented on GitHub (Jan 10, 2024): If you can give us a python sample that also repros the issue, that'd be most curious for sure. But I sure haven't ever seen anything like that in my time with python 😄 Maybe there's something weird about the way PowerShell is escaping the file name, since it's got the `$` in it? But I'd suspect that to be less likely
Author
Owner

@deadcoder0904 commented on GitHub (Jan 10, 2024):

@zadjii-msft sure, i wasn't kidding. it is definitely weird.

i asked chatgpt here:

image

you can open it here although the code was chatgpt-generated in an earlier thread that i pasted in the 1st comment.

see this code for the strip function:

import os
import sys
from moviepy.editor import VideoFileClip

def calculate_total_duration(folder_path):
    total_duration = 0

    for root, dirs, files in os.walk(folder_path):
        for file in files:
            if file.lower().endswith(('.mp4', '.mkv', '.ts')):
                video_path = os.path.join(root, file)
                clip = VideoFileClip(video_path)
                total_duration += clip.duration
                clip.close()

    total_hours = int(total_duration // 3600)
    total_minutes = int((total_duration % 3600) // 60)
    total_seconds = int(total_duration % 60)

    print(f"Total Duration: {total_hours} hours, {total_minutes} minutes, {total_seconds} seconds")

if __name__ == "__main__":
    if len(sys.argv) != 2:
        print("Usage: python file.py <folder_path>")
        sys.exit(1)

    folder_path = os.path.abspath(sys.argv[1].strip('"'))

    if not os.path.exists(folder_path):
        print(f"Error: The specified folder '{folder_path}' does not exist.")
        sys.exit(1)

    calculate_total_duration(folder_path)

and here's a screenshot of my terminal:

image

it works because of that strip function which shouldn't be there either.

@deadcoder0904 commented on GitHub (Jan 10, 2024): @zadjii-msft sure, i wasn't kidding. it is definitely weird. i asked chatgpt here: ![image](https://github.com/microsoft/terminal/assets/16436270/f0b38a75-1cd6-48d5-bc0d-47ae217cecbd) you can [open it here](https://chat.openai.com/share/82a3948c-aff6-44c9-b41f-01331e9372ab) although the code was chatgpt-generated in an earlier thread that i pasted in the 1st comment. see this code for the `strip` function: ```python import os import sys from moviepy.editor import VideoFileClip def calculate_total_duration(folder_path): total_duration = 0 for root, dirs, files in os.walk(folder_path): for file in files: if file.lower().endswith(('.mp4', '.mkv', '.ts')): video_path = os.path.join(root, file) clip = VideoFileClip(video_path) total_duration += clip.duration clip.close() total_hours = int(total_duration // 3600) total_minutes = int((total_duration % 3600) // 60) total_seconds = int(total_duration % 60) print(f"Total Duration: {total_hours} hours, {total_minutes} minutes, {total_seconds} seconds") if __name__ == "__main__": if len(sys.argv) != 2: print("Usage: python file.py <folder_path>") sys.exit(1) folder_path = os.path.abspath(sys.argv[1].strip('"')) if not os.path.exists(folder_path): print(f"Error: The specified folder '{folder_path}' does not exist.") sys.exit(1) calculate_total_duration(folder_path) ``` and here's a screenshot of my terminal: ![image](https://github.com/microsoft/terminal/assets/16436270/90da0960-82a0-4a1e-844f-2736d7da5c00) it works because of that `strip` function which shouldn't be there either.
Author
Owner

@deadcoder0904 commented on GitHub (Jan 10, 2024):

and bdw you can see how the ` is added before $ in the terminal screenshot.

i couldn't debug it for the life of me & changed programming languages 5 times bcz i thought it was programming language issue. maybe its windows or powershell or terminal bcz python & deno both got it.

@deadcoder0904 commented on GitHub (Jan 10, 2024): and bdw you can see how the ` is added before $ in the terminal screenshot. i couldn't debug it for the life of me & changed programming languages 5 times bcz i thought it was programming language issue. maybe its windows or powershell or terminal bcz python & deno both got it.
Author
Owner

@jamespack commented on GitHub (Jan 10, 2024):

and bdw you can see how the ` is added before $ in the terminal screenshot.

Powershell is escaping the in that string because means something in powerhshell.

image

@jamespack commented on GitHub (Jan 10, 2024): > and bdw you can see how the ` is added before $ in the terminal screenshot. Powershell is escaping the $ in that string because $ means something in powerhshell. ![image](https://github.com/microsoft/terminal/assets/2086722/5a8ac9a1-f209-4c53-beee-a10d9cb7c3a7)
Author
Owner

@zadjii-msft commented on GitHub (Jan 10, 2024):

Huh.

test.py:

import os
import sys
if __name__ == "__main__":
    if len(sys.argv) != 2:
        print("Usage: python test.py <folder_path>")
        sys.exit(1)

    arg = sys.argv[1]
    folder_path = os.path.abspath(sys.argv[1].strip('"'))

    print(f"arg: {arg}")
    print(f"folder_path: {folder_path}")

image

The only case where I got a trailing slash in the args to python, was in CMD, when I manually added a trailing slash to the command (tab complete didn't give me one). And in that case, that makes sense - CreateProcess would definitely use that to escape the " and pass it literally

@zadjii-msft commented on GitHub (Jan 10, 2024): Huh. `test.py`: ```py import os import sys if __name__ == "__main__": if len(sys.argv) != 2: print("Usage: python test.py <folder_path>") sys.exit(1) arg = sys.argv[1] folder_path = os.path.abspath(sys.argv[1].strip('"')) print(f"arg: {arg}") print(f"folder_path: {folder_path}") ``` ![image](https://github.com/microsoft/terminal/assets/18356694/37a665d0-7f34-49a2-bf20-1390a34134e2) The only case where I got a trailing slash in the args to python, was in CMD, when I manually added a trailing slash to the command (tab complete didn't give me one). And in that case, that makes sense - CreateProcess would definitely use that to escape the `"` and pass it literally
Author
Owner

@deadcoder0904 commented on GitHub (Jan 11, 2024):

@zadjii-msft im not sure what terminal you are using.

i'm using windows terminal with default profile as powershell i think.

if its the same then its definitely weird.

and i've tested in 2 different windows installations (one in my laptop which is windows 11 & another on my pc which is windows 10)

@deadcoder0904 commented on GitHub (Jan 11, 2024): @zadjii-msft im not sure what terminal you are using. i'm using windows terminal with default profile as powershell i think. if its the same then its definitely weird. and i've tested in 2 different windows installations (one in my laptop which is windows 11 & another on my pc which is windows 10)
Author
Owner

@deadcoder0904 commented on GitHub (Jan 15, 2024):

so the solution is to use powershell 7 because powershell 5 has halted development since 8 years (2016) as mentioned here

@deadcoder0904 commented on GitHub (Jan 15, 2024): so the solution is to use powershell 7 because powershell 5 has halted development since 8 years (2016) as mentioned [here](https://github.com/orgs/PowerShell/discussions/21065)
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: starred/terminal#21063