
Research
/Security News
Toptal’s GitHub Organization Hijacked: 10 Malicious Packages Published
Threat actors hijacked Toptal’s GitHub org, publishing npm packages with malicious payloads that steal tokens and attempt to wipe victim systems.
The module provides primitives for string and text manipulation.
StringEditor
class provided by Gapotchenko.FX.Text
module allows you to perform an iterative random-access editing of a string.
It is primarily designed to work in conjunction with Regex
class from System.Text.RegularExpressions
namespace to efficiently handle an advanced set of tasks
when functionality provided by conventional methods like Regex.Replace
is just not enough.
Regex trampolines are special functions that allow to gradually convert the conventional string manipulation code into one that uses regex semantics.
Let's take a look on example:
if (name.Equals("[mscorlib]System.Object", StringComparison.Ordinal))
Console.WriteLine("The name represents a system object.");
The given code is later changed in order to cover the new requirements:
if (name.Equals("[mscorlib]System.Object", StringComparison.Ordinal) ||
name.Equals("[netstandard]System.Object", StringComparison.Ordinal) ||
name.Equals("[System.Runtime]System.Object", StringComparison.Ordinal))
{
Console.WriteLine("The name represents a system object.");
}
It does the job but such mechanical changes may put a toll on code maintainability when they accumulate. You can also spot some amount of code duplication here.
Another approach would be to use Regex
class which is readily available in .NET.
But that might destroy the expressiveness of string manipulation functions like Equals
.
If a string function takes a StringComparison
parameter then it may become a significant challenge to reliably refactor it to Regex
implementation.
That's why Gapotchenko.FX.Text
module provides a set of so called regex trampoline functions.
They look exactly like Equals
, StartsWith
, EndsWith
, IndexOf
but work with regex patterns instead of raw strings.
They also end with Regex
suffix in their names, so Equals
becomes EqualsRegex
, StartsWith
correspondingly becomes StartsWithRegex
, and so on.
And this is how a regex trampoline can be used for the given sample in order to meet the new requirements by a single line change:
using Gapotchenko.FX.Text.RegularExpressions;
if (name.EqualsRegex(@"\[(mscorlib|netstandard|System\.Runtime)]System\.Object", StringComparison.Ordinal))
Console.WriteLine("The name represents a system object.");
An immediate improvement in expressiveness without duplication.
StringBuilder.AppendJoin
is a method that appeared in later versions of .NET platform.
Gapochenko.FX provides a corresponding polyfill that can be used in code targeting older .NET versions.
The benefit of this method is that it combines string.Join
and StringBuilder.Append
operations in one method,
while using the underlying efficiency of the StringBuilder
.
Gapotchenko.FX.Text.StringEditor
Let's continue with a look at some other modules provided by Gapotchenko.FX:
Or look at the full list of modules.
FAQs
Provides primitives for string and text manipulation.
We found that gapotchenko.fx.text demonstrated a healthy version release cadence and project activity because the last version was released less than 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
/Security News
Threat actors hijacked Toptal’s GitHub org, publishing npm packages with malicious payloads that steal tokens and attempt to wipe victim systems.
Research
/Security News
Socket researchers investigate 4 malicious npm and PyPI packages with 56,000+ downloads that install surveillance malware.
Security News
The ongoing npm phishing campaign escalates as attackers hijack the popular 'is' package, embedding malware in multiple versions.