
Research
PyPI Package Disguised as Instagram Growth Tool Harvests User Credentials
A deceptive PyPI package posing as an Instagram growth tool collects user credentials and sends them to third-party bot services.
filename-reserved-regex
Advanced tools
Regular expression for matching reserved filename characters
The filename-reserved-regex npm package provides a regular expression that matches characters that are reserved in filenames across different operating systems. This can be particularly useful for validating filenames or sanitizing them to ensure they are compatible across Windows, macOS, and Unix/Linux systems.
Validation of filenames
This code sample demonstrates how to use the package to check if a string (which is intended to be used as a filename) contains any reserved characters. The `match` method will return an array of matches if any reserved characters are found, or `null` if the filename is safe to use.
"some*filename?.txt".match(filenameReservedRegex())
Sanitization of filenames
This code sample shows how to sanitize a filename by removing any reserved characters. This is done by replacing any characters that match the regex provided by the package with an empty string, effectively removing them.
"some*filename?.txt".replace(filenameReservedRegex(), '')
The sanitize-filename package is designed to sanitize a string to ensure it is a valid filename. Unlike filename-reserved-regex, which provides a regex for matching reserved characters, sanitize-filename actively sanitizes the string, making it safe for use as a filename without requiring additional steps.
filenamify is another package that converts a string into a valid filename. It goes beyond just removing reserved characters by also truncating the string to a valid length and optionally replacing removed characters with a specified replacement. This makes it a more comprehensive solution compared to filename-reserved-regex, which focuses solely on providing the regex for reserved characters.
Regular expression for matching reserved filename characters
On Unix-like systems /
is reserved and <>:"/\|?*
as well as non-printable characters \u0000-\u001F
on Windows.
$ npm install filename-reserved-regex
import filenameReservedRegex, {windowsReservedNameRegex} from 'filename-reserved-regex';
filenameReservedRegex().test('foo/bar');
//=> true
filenameReservedRegex().test('foo-bar');
//=> false
'foo/bar'.replace(filenameReservedRegex(), '!');
//=> 'foo!bar'
windowsReservedNameRegex().test('aux');
//=> true
Returns a regex that matches all invalid characters.
Returns an exact-match case-insensitive regex that matches invalid Windows
filenames. These include CON
, PRN
, AUX
, NUL
, COM1
, COM2
, COM3
, COM4
, COM5
,
COM6
, COM7
, COM8
, COM9
, LPT1
, LPT2
, LPT3
, LPT4
, LPT5
, LPT6
, LPT7
, LPT8
and LPT9
.
FAQs
Regular expression for matching reserved filename characters
The npm package filename-reserved-regex receives a total of 5,174,290 weekly downloads. As such, filename-reserved-regex popularity was classified as popular.
We found that filename-reserved-regex demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Research
A deceptive PyPI package posing as an Instagram growth tool collects user credentials and sends them to third-party bot services.
Product
Socket now supports pylock.toml, enabling secure, reproducible Python builds with advanced scanning and full alignment with PEP 751's new standard.
Security News
Research
Socket uncovered two npm packages that register hidden HTTP endpoints to delete all files on command.