Research
Security News
Malicious npm Packages Inject SSH Backdoors via Typosquatted Libraries
Socket’s threat research team has detected six malicious npm packages typosquatting popular libraries to insert SSH backdoors.
mustermann-visualizer
Advanced tools
With this gem, you can visualize the internal structure of a Mustermann pattern:
Loading mustermann/visualizer
will automatically add to_html
and to_ansi
to pattern objects.
require 'mustermann/visualizer'
puts Mustermann.new('/:name').to_ansi
puts Mustermann.new('/:name').to_html
Alternatively, you can also create a separate highlight
object, which allows finer grained control and more formats:
require 'mustermann/visualizer'
pattern = Mustermann.new('/:name')
highlight = Mustermann::Visualizer.highlight(pattern)
puts highlight.to_ansi
inspect
modeBy default, the highlighted string will be a colored version of to_s
. It is also possible to produce a colored version of inspect
require 'mustermann/visualizer'
pattern = Mustermann.new('/:name')
# directly from the pattern
puts pattern.to_ansi(inspect: true)
# via the highlighter
highlight = Mustermann::Visualizer.highlight(pattern, inspect: true)
puts highlight.to_ansi
element | inherits style from | default theme | note |
---|---|---|---|
default | #839496 | ANSI \e[10m if not set | |
special | default | #268bd2 | |
capture | special | #cb4b16 | |
name | #b58900 | always inside capture | |
char | default | ||
expression | capture | only exists in URI templates | |
composition | special | meta style, does not exist directly | |
group | composition | ||
union | composition | ||
optional | special | ||
root | default | wraps the whole pattern | |
separator | char | #93a1a1 | |
splat | capture | ||
named_splat | splat | ||
variable | capture | always inside expression | |
escaped | char | #93a1a1 | |
escaped_char | always inside escaped | ||
quote | special | ||
illegal | special | #8b0000 |
You can set theme any of the above elements. The default theme will only be applied if no custom theming is used.
# custom theme with highlight object
highlight = Mustermann::Visualizer.highlight(pattern, special: "#08f")
puts highlight.to_ansi
Themes apply both to ANSI and to HTML/CSS output. The exact ANSI code used depends on the terminal and its capabilities.
By default, the syntax elements will be translated into span
tags with style
attributes.
Mustermann.new('/:name').to_html
<span style="color: #839496;"><span style="color: #93a1a1;">/</span><span style="color: #cb4b16;">:<span style="color: #b58900;">name</span></span></span></span>
You can also set the css
option to true
to make it include a stylesheet instead.
Mustermann.new('/:name').to_html(css: true)
<span class="mustermann_pattern"><style type="text/css">
.mustermann_pattern .mustermann_name {
color: #b58900;
}
/* ... etc ... */
</style><span class="mustermann_root"><span class="mustermann_separator">/</span><span class="mustermann_capture">:<span class="mustermann_name">name</span></span></span></span>
Or you can set it to false
, which will omit style
attributes, but include class
attributes.
<span class="mustermann_pattern"><span class="mustermann_root"><span class="mustermann_separator">/</span><span class="mustermann_capture">:<span class="mustermann_name">name</span></span></span></span>
It is possible to change the class prefix and the tag used.
Mustermann.new('/:name').to_html(css: false, class_prefix: "mm_", tag: "tt")
<tt class="mm_pattern"><tt class="mm_root"><tt class="mm_separator">/</tt><tt class="mm_capture">:<tt class="mm_name">name</tt></tt></tt></tt>
If you create a highlight object, you can ask it for its stylesheet
.
<% highlight = Mustermann::Visualizer.highlight("/:name") %>
<html>
<head>
<style type="text/css">
<%= highlight.stylesheet %>
</style>
</head>
<body>
<%= highlight.to_html(css: false) %>
</body>
</html>
If you create a highlight object, you have two other formats available: Hansi template strings and s-expression like strings. These might be useful if you want to check how a theme will be applied or as intermediate format for highlighting by other means.
require 'mustermann/visualizer'
highlight = Mustermann::Visualizer.highlight("/:page")
puts highlight.to_hansi_template
puts highlight.to_sexp
Hansi template strings wrap elements in tags that are similar to XML tags (though they are not, entity encoding and attributes are not supported, escaping works with a slash, so an escaped >
would be \>
, not >
).
<pattern><root><separator>/</separator><capture>:<name>page</name></capture></root></pattern>
The s-expression like syntax looks as follows:
(root (separator /) (capture : (name page)))
When mustermann
is being loaded from within an IRB or Pry session, it will automatically load mustermann/visualizer
too, if possible.
When displayed as result, it will be highlighted.
In Pry, this will even work when nested inside other objects (like as element on an array).
Loading mustermann/visualizer
will automatically add to_tree
to pattern objects.
require 'mustermann/visualizer'
puts Mustermann.new("/:page(.:ext)?/*action").to_tree
For patterns not based on an AST (shell, simple, regexp), it will print out a single line:
pattern (not AST based) "/example"
It will display a tree for identity patterns. While these are not based on an AST internally, Mustermann supports generating an AST for these patterns.
FAQs
Unknown package
We found that mustermann-visualizer 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
Security News
Socket’s threat research team has detected six malicious npm packages typosquatting popular libraries to insert SSH backdoors.
Security News
MITRE's 2024 CWE Top 25 highlights critical software vulnerabilities like XSS, SQL Injection, and CSRF, reflecting shifts due to a refined ranking methodology.
Security News
In this segment of the Risky Business podcast, Feross Aboukhadijeh and Patrick Gray discuss the challenges of tracking malware discovered in open source softare.