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

skip extension if no ext found #425

Merged
merged 8 commits into from
Oct 18, 2020
Merged

skip extension if no ext found #425

merged 8 commits into from
Oct 18, 2020

Conversation

zwpaper
Copy link
Member

@zwpaper zwpaper commented Oct 2, 2020

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. @meain

ls:

[root@b78708e2fc75 tmp]# \ls
'5a35.ico'$'\247\375''='$'\356\324\373\206\362\300''^m'$'\330'

lsd:

[root@b78708e2fc75 tmp]# lsd
 5a35.ico��=������^m�

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 �

@codecov-commenter
Copy link

codecov-commenter commented Oct 2, 2020

Codecov Report

Merging #425 into master will increase coverage by 0.03%.
The diff coverage is 100.00%.

Impacted file tree graph

@@            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     
Impacted Files Coverage Δ
src/meta/name.rs 93.80% <100.00%> (+0.76%) ⬆️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 4991436...2363960. Read the comment docs.

@zwpaper
Copy link
Member Author

zwpaper commented Oct 2, 2020

BTW, I have tried to find a way to escape the invalid utf-8 code in the filename, but no luck.

path.file_name() returns an Option<&OsStr>, If invalid utf-8 contained, it was None, I can not find a way to get the name, can u give me some tips for getting it? even we did not need to print it in lsd, just out of curiosity.

@Peltoche
Copy link
Collaborator

Peltoche commented Oct 2, 2020

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.

@zwpaper
Copy link
Member Author

zwpaper commented Oct 2, 2020

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,
and rust keeps preventing me create the invalid utf-8 char.

unicode escape must not be a surrogate always happens after invalid utf-8 chars added

Comment on lines 373 to 394
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");
Copy link
Contributor

@0jdxt 0jdxt Oct 6, 2020

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')"
Suggested change
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");

Copy link
Member Author

@zwpaper zwpaper Oct 7, 2020

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=`
',

Copy link
Member Author

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-io
Copy link

codecov-io commented Oct 7, 2020

Codecov Report

Merging #425 into master will increase coverage by 0.16%.
The diff coverage is 100.00%.

Impacted file tree graph

@@            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     
Impacted Files Coverage Δ
src/meta/name.rs 93.80% <100.00%> (+0.76%) ⬆️
tests/integration.rs 100.00% <100.00%> (ø)

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update ae92912...ef849b6. Read the comment docs.

@zwpaper zwpaper force-pushed the master branch 2 times, most recently from d37b5bf to 3529edc Compare October 7, 2020 09:46
Comment on lines 369 to 376
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");
Copy link
Contributor

@0jdxt 0jdxt Oct 7, 2020

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

Suggested change
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();

Copy link
Member Author

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

Copy link
Contributor

@0jdxt 0jdxt Oct 7, 2020

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'.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

that's really weird, I can't reproduce your result
image

Copy link
Member

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?

Copy link
Member Author

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

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the same result on debian 10 in fusion vm.

image

@0jdxt could you help me to reproduce this?

Copy link
Contributor

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.

@zwpaper
Copy link
Member Author

zwpaper commented Oct 8, 2020

@0jdxt thanks for the improvement

@meain This should be ready to go

@0jdxt
Copy link
Contributor

0jdxt commented Oct 8, 2020

I submitted a small pr to tidy my code a bit

@zwpaper
Copy link
Member Author

zwpaper commented Oct 17, 2020

@meain this is ready to go, what's your idea?

@meain
Copy link
Member

meain commented Oct 17, 2020

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.

@zwpaper
Copy link
Member Author

zwpaper commented Oct 17, 2020

@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.

@meain
Copy link
Member

meain commented Oct 17, 2020

Yes, but the chances of user having an invalid utf-8 char in the filename is very unlikely.
Considering that, having this message in the project description does not seem right.

Plus, � seems like something that the user would be able to figure out to be a "non-standard" entry.
I am expecting only a few handful of users to ever run into this and if it ever comes to that, I think we could probably add it to the FAQ section of the readme.

@zwpaper
Copy link
Member Author

zwpaper commented Oct 17, 2020

@meain moved to FAQ

@0jdxt
Copy link
Contributor

0jdxt commented Oct 17, 2020

hey, you somehow got rid of some of my commits? the tests now have the old macro. Did you do a rebase?

@zwpaper
Copy link
Member Author

zwpaper commented Oct 17, 2020

@0jdxt oh, it was my bad! I forgot to pull your work, so lucky that you found it!

@0jdxt
Copy link
Contributor

0jdxt commented Oct 17, 2020

Btw don't merge my pr its wrong atm

zwpaper and others added 2 commits October 17, 2020 22:04
tidy up macro

reduce reallocations

macro to function

tidy w/ import

add EOL
@zwpaper
Copy link
Member Author

zwpaper commented Oct 17, 2020

@meain sorry for the accident, this should be ready to go

@meain
Copy link
Member

meain commented Oct 18, 2020

Thanks @zwpaper and @0jdxt . Also thanks for filling in the CHANGELOG.md file.

@meain meain merged commit 7c971e7 into lsd-rs:master Oct 18, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

lsd panics
6 participants