-
-
Notifications
You must be signed in to change notification settings - Fork 420
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
skip extension if no ext found #425
Conversation
Codecov Report
@@ Coverage Diff @@
## master #425 +/- ##
==========================================
+ Coverage 77.74% 77.77% +0.03%
==========================================
Files 34 34
Lines 3329 3325 -4
==========================================
- Hits 2588 2586 -2
+ Misses 741 739 -2
Continue to review full report at Codecov.
|
BTW, I have tried to find a way to escape the invalid utf-8 code in the filename, but no luck.
|
Hello @zwpaper, thanks for this PR. Can you add a test with the filename from the issue? This would allow us to confirm that the code work as expected and to avoid any future regression. |
Hi @Peltoche , glad that you have time for lsd again 😃 I have tried to add the test for this, but this happened only if there is an invalid utf-8 char,
|
tests/integration.rs
Outdated
Command::new("python3") | ||
.arg("-c") | ||
.arg(r#"import pathlib; pathlib.Path('/tmp/bad.extension/bad.extension\udca7\udcfd').touch()"#) | ||
.output() | ||
.expect("failed to create file"); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hey man it may be best to avoid having python as a dependency, this can be done in sh with
$ sh -c "touch $(printf 'bad.extension\xdca7\xdcfd')"
Command::new("python3") | |
.arg("-c") | |
.arg(r#"import pathlib; pathlib.Path('/tmp/bad.extension/bad.extension\udca7\udcfd').touch()"#) | |
.output() | |
.expect("failed to create file"); | |
Command::new("sh") | |
.arg("-c") | |
.arg("touch $(printf '/tmp/bad.extension/bad.extension\xdca7\xdcfd')") | |
.output() | |
.expect("failed to create file"); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't want the python dep either, but I can not find a way to create the invalid utf-8 name even use your code.🤣
I have tried the solution like this, The output of the sh -c touch
is iliteral \xdca7
, not an utf-8 code.
invalid utf-8 code will be treated as error if using double quote.
---- test_bad_utf_8_extension stdout ----
thread 'test_bad_utf_8_extension' panicked at 'Unexpected stdout, failed var.is_match(bad.extension��
$)
└── var as str: bad.extension\xdca7\xdcfd
command=`"/root/lsd/target/debug/lsd" "/tmp/.tmpRDHlAb"`
code=0
stdout=`bad.extension\xdca7\xdcfd
`
stderr=`
',
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I was still trying to find a way to create the invalid name by shell
, but no luck, python is my last choice...
Codecov Report
@@ Coverage Diff @@
## master #425 +/- ##
==========================================
+ Coverage 78.36% 78.53% +0.16%
==========================================
Files 34 34
Lines 3342 3359 +17
==========================================
+ Hits 2619 2638 +19
+ Misses 723 721 -2
Continue to review full report at Codecov.
|
d37b5bf
to
3529edc
Compare
tests/integration.rs
Outdated
Command::new("python3") | ||
.arg("-c") | ||
.arg(format!( | ||
r#"import pathlib; pathlib.Path('{}/bad.extension\udca7\udcfd').touch()"#, | ||
tmp.path().to_str().unwrap() | ||
)) | ||
.output() | ||
.expect("failed to create file"); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
try with double slashes, works for me
Command::new("python3") | |
.arg("-c") | |
.arg(format!( | |
r#"import pathlib; pathlib.Path('{}/bad.extension\udca7\udcfd').touch()"#, | |
tmp.path().to_str().unwrap() | |
)) | |
.output() | |
.expect("failed to create file"); | |
Command::new("sh") | |
.arg("-c") | |
.arg("touch $(printf 'bad.extension\\xdca7\\xdcfd')") | |
.output() | |
.unwrap(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
have your try to run the code?
double backslashes fix the rust error report, but created a file named 'bad.extension\xdca7\xdcfd'
not the utf 8 code.
I have done several tries before using python
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah I did a project with main.rs
:
use std::process::Command;
fn main() {
Command::new("sh")
.arg("-c")
.arg("touch $(printf 'bad.extension\\xdca7\\xdcfd')")
.output()
.unwrap();
}
and when i run ls
i get 'bad.extension'$'\334''a7'$'\334''fd'
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@zwpaper Are you running from within a linux docker image on a mac?
Is it possible that that could affect the result?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
that's also my concern, so I was setting up a VM in fusion, big sur broke my VirtualBox
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'll submit a PR just to see if it works with the CI.
I submitted a small pr to tidy my code a bit |
@meain this is ready to go, what's your idea? |
Hey, I don't think there is a need to explicitly mention this in the readme under description as this is a really small edge case and an implementation detail. |
@meain I added because this affects the user experience. Users will get unexpected � when an invalid utf-8 appeared in the file name, so we should tell them about this. |
Yes, but the chances of user having an invalid utf-8 char in the filename is very unlikely. Plus, � seems like something that the user would be able to figure out to be a "non-standard" entry. |
@meain moved to FAQ |
hey, you somehow got rid of some of my commits? the tests now have the old macro. Did you do a rebase? |
@0jdxt oh, it was my bad! I forgot to pull your work, so lucky that you found it! |
Btw don't merge my pr its wrong atm |
tidy up macro reduce reallocations macro to function tidy w/ import add EOL
@meain sorry for the accident, this should be ready to go |
fix #387
I also found the output is a little bit different like ls, as
lsd
will display the UTF-8 in file names, It seems like work as expect IMO. If necessary we can discuss this in a new issue. @meainls:
lsd:
FYI:
the utf8 code in the filename is reserved for utf-16(https://en.wikipedia.org/wiki/UTF-16#U+D800_to_U+DFFF), and rust will check this by default.
Following the rust way, we display the reserved chars as �