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

BUG: withExtension is very broken, mangling file some names #75

Open
229c9cf0 opened this issue Feb 23, 2022 · 1 comment
Open

BUG: withExtension is very broken, mangling file some names #75

229c9cf0 opened this issue Feb 23, 2022 · 1 comment

Comments

@229c9cf0
Copy link

I was wondering why my iwq_extended queue would always be missed by adds, with them instead ending up in iwq_extende instead. Yet targeting iwq_extended_ would put them there... Turns out rtrim is either completely broken or working exactly as intended but a very wrong tool for the job:

"extended.md".rtrim(".md") // --> "extende"
"extendeddddddd.md".rtrim(".md") // --> "extende"
"extendedmmd.d.d.....mmmmdddmmmm......".rtrim(".md") // --> "extende"

Given that "add to queue" already adds the extension, I have no clue what the .rtrim(".md") + ".md" was supposed to achieve. (rtrim is also used at least to generate status bar text, so that's not the only problem.)

@229c9cf0
Copy link
Author

I don't really know JS, but with some experimentation it seems that something like

String.prototype.rcut = function( ext ) {
  return this.substr( 0, this.lastIndexOf( ext ) ) || this;
}

would do a much better job for the intended purpose here. (No clue if that already has a common name, this one's made up.) It's still not fully correct, since .rcut(".") would remove anything after a dot (instead maybe checking the length of the extension is its offset from the end or something like that would be more precise), but way better than rtrim, which removes all characters repeatedly. (Which seems to be a PHP-ism and working as intended, so the name rtrim SHOULD NOT be used for a different purpose, especially since you're adding it as a public function on String.)

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

No branches or pull requests

1 participant