Skip to content

Interpret control characters pasted into -LiteralPath arguments as verbatim characters. #4072

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

Closed
1 task done
RokeJulianLockhart opened this issue Jul 11, 2024 · 3 comments
Labels
Issue-Enhancement It's a feature request.

Comments

@RokeJulianLockhart
Copy link

RokeJulianLockhart commented Jul 11, 2024

Prerequisites

  • Write a descriptive title.

Description of the new feature/enhancement

As PowerShell/PowerShell#24037 (comment) explains:

Expected behaviour

Originally, this issue was going to be about how PowerShell can't handle certain legal UTF-8 characters in inode paths. However, after creating a test script:

#!/usr/bin/env pwsh

# Prerequisites
# -------------

	# ~~~pwsh
	# #Requires -PSEdition 'Core'
	# #Requires -Version 7
	# ~~~
	
	Set-Location -LiteralPath "$HOME"

# Example Directory
# -----------------

	# Creates an example directory.
	
	$DirectoryPath = 'TabPrefixed	ExampleDirectory.dir'
	$PrintPath = "$DirectoryPath"
	Write-Output (Show-Markdown -InputObject "The path is ``$PrintPath``.")
	
	New-Item `
		-Path "$HOME" `
		-Name "$DirectoryPath" `
		-ItemType 'directory'

# Example File
# ------------

	# Creates an example file.
	
	$FilePath = 'TabPrefixed	ExampleFile.txt'
	$PrintPath = "$FilePath"
	Write-Output (Show-Markdown -InputObject "The path is ``$PrintPath``.")
	
	New-Item `
		-Path ("$HOME" + [IO.Path]::DirectorySeparatorChar + "$DirectoryPath") `
		-Name "$FilePath" `
		-ItemType 'file' `
		-Value 'Example text.'

# Path Acquisition
# ----------------

	# Lists both.
	
	$FullFilePath = (`
	Get-ChildItem `
		-LiteralPath (
			"$HOME"          + [IO.Path]::DirectorySeparatorChar +
			"$DirectoryPath" + [IO.Path]::DirectorySeparatorChar +
			"$FilePath")
		)[0] | Select-Object -ExpandProperty 'FullName'

# File Content Acquisition
# ------------------------

	# This should fail.
	
	$PrintPath = "$FullFilePath"
	Write-Output (Show-Markdown -InputObject "The path is ``$PrintPath``.")
	
	Get-Content -LiteralPath "$FullFilePath"
	Write-Output $?

I realized that it could. Instead, I've narrowed it to a fault in how PowerShell, via Konsole and VSCode's terminals, interprets certain characters (like - tabs) as control codes.

Steps to reproduce

Try pasting your equivalent to the undermentioned command:

#!/usr/bin/env pwsh
Get-Content -LiteralPath '/home/RokeJulianLockhart/TabPrefixed    ExampleDirectory.dir/TabPrefixed        ExampleFile.txt'

...into the shell after successfully invoking it.

This value is able to be acquired by the undermentioned command:

#!/usr/bin/env pwsh
(Get-ChildItem -LiteralPath "$DirectoryPath")[0].FullName

Actual behavior

  1. The undermentioned is a command that has been pasted:

    #!/usr/bin/env pwsh
    Get-Content -LiteralPath "/home/RokeJulianLockhart/Documents/pyside6/prefix^Iexample.txt/example.txt"

    Note within it, the "prefix^Iexample". The original content does not contain that control code.

  2. Alternatively, sometimes, it appears to paste the path correctly, but doesn't recognise the value unless passed in a script:

    1. PS /home/RokeJulianLockhart> (Get-ChildItem -LiteralPath "$DirectoryPath")[0].FullName
      /home/RokeJulianLockhart/TabPrefixed    ExampleDirectory.dir/TabPrefixed        ExampleFile.txt
    2. PS /home/RokeJulianLockhart> Get-Content -LiteralPath '/home/RokeJulianLockhart/TabPrefixed    ExampleDirectory.dir/TabPrefixed        ExampleFile.txt'                                                                                                                                 
      Get-Content: Cannot find path '/home/RokeJulianLockhart/TabPrefixed    ExampleDirectory.dir/TabPrefixed        ExampleFile.txt' because it does not exist.
    3. PS /home/RokeJulianLockhart> Get-Content -LiteralPath "$FullFilePath"                                                                                  
      Example text.
    4. PS /home/RokeJulianLockhart> Write-Output "$FullFilePath"            
      /home/RokeJulianLockhart/TabPrefixed    ExampleDirectory.dir/TabPrefixed        ExampleFile.txt

Visuals

Screencast_20240710_125007.webm

Proposed technical implementation details (optional)

No response

@daxian-dbw
Copy link
Member

daxian-dbw commented Jul 11, 2024

Please keep the discussion in PowerShell repo for now. When it's time to open an issue here, you need to follow the template to describe the issue, not just referring to another issue.

@microsoft-github-policy-service microsoft-github-policy-service bot removed the Needs-Triage 🔍 It's a new issue that core contributor team needs to triage. label Jul 11, 2024
@RokeJulianLockhart
Copy link
Author

RokeJulianLockhart commented Jul 12, 2024

#4072 (comment)

@daxian-dbw, best to close as invalid (rather than completed) since this hasn't been completed. If you relinquish triage control to me, I can mark it as a duplicate of #4447 (comment), formally linking them.

@RokeJulianLockhart
Copy link
Author

RokeJulianLockhart commented Feb 4, 2025

#4072 (comment)

@daxian-dbw, refiled at #4447 (comment). Thank you.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Issue-Enhancement It's a feature request.
Projects
None yet
Development

No branches or pull requests

2 participants