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.
Talius is a parser for CSS selectors. It does not parse CSS, just CSS selectors.
Talius.new
accepts a single string as the selector. The Talius
object provides an interface with which to access the properties of that
selector.
In this example, the selector consists of just a
, meaning it selects
<a>
tags:
raw = 'a'
selector = Talius.new(raw)
rule = selector.rules[0]
rule.tags # => {"a"=>{"name"=>"a"}}
Line 1 creates the raw CSS selector like you might find in a CSS file. Line 2
creates a Talius
object.
Each Talius has one or more rules. In this example the object will have one
rule. Line 3 gets that rule. Each rule has a hash of tag names in the tags
property. Line 4 displays that hash. See below for more about the tags
hash.
The following sections will describe how Talius provides information about different elements of a selector. Talius is in its infancy, so there are some important aspects of CSS selectors that it doesn't support. Those aspects are detailed below.
If a selector contains a tag name, that information will be put into the
tags
hash of the rule. Consider this example.
raw = 'a'
selector = Talius.new(raw)
rule = selector.rules[0]
rule.tags # => {"a"=>{"name"=>"a"}}
rule.tags['a'].class # => Talius::Node::Tag
rule.tags['a'].name # => "a"
rule.tags['a'].namespace # => nil
That selector consists of just a single tag name, so the selector
object has
just one rule. That rule has a property called tags
, which is a hash of the
tags in the rule. The key for each hash element is the name of the tag. The
value of the element is a Talius::Node::Tag
object. That object has two
properties, name
and namespace
.
To indicate the namespace for the tag, put the namespace, followed by |
,
followed by the name of the tag. For example, the following code has a selector
for tags in the mml
namespace with the name a
. The keys in the tags
hash
are formatted in the same way.
raw = 'mml|a'
selector = Talius.new(raw)
rule = selector.rules[0]
rule.tags # => {"mml|a"=>{"name"=>"a", "namespace"=>"mml"}}
rule.tags['mml|a'].class # => Talius::Node::Tag
rule.tags['mml|a'].name # => "a"
rule.tags['mml|a'].namespace # => "mml"
For multiple rules for a selector, separate the rules with a comma. For example,
the following code parses a selector with two rules, one for the section
tag
and one for the div
tag.
raw = 'section, div'
selector = Talius.new(raw)
selector.rules.length # => 2
selector.rules # => [{"tags"=>{"section"=>{"name"=>"section"}}}, {"tags"=>{"div"=>{"name"=>"div"}}}]
If any ID descriptions are given, those IDs can be found in the rule's ids
hash. The keys are the names of the IDs, the values are always true
.
raw = '#overview'
selector = Talius.new(raw)
rule = selector.rules[0]
rule.ids # => {"overview"=>true}
Classes are available in the classes
property of the rule. classes
is a
simple hash in which the value of each class is true.
raw = 'section.overview.current'
selector = Talius.new(raw)
rule = selector.rules[0]
rule.classes # => {"overview"=>true, "current"=>true}
Attribute rules are provided in the rule's atts
hash. The hash consists of the
key of each attribute and a Talius::Node::Att
object.
In this simple example, the selector looks for tags with an rel
attribute.
raw = '[rel]'
selector = Talius.new(raw)
rule = selector.rules[0]
att = rule.atts['rel']
att.class # => Talius::Node::Att
att.name # => rel
If you assign a value to the attribute, that value will be in value
property.
raw = '[rel=license]'
selector = Talius.new(raw)
rule = selector.rules[0]
att = rule.atts['rel']
att.name # => href
att.value # => license
Attribute namespaces are indicated in the same way as with tags. You can access
the namespace with the namespace
property.
raw = '[mml|rel]'
selector = Talius.new(raw)
rule = selector.rules[0]
att = rule.atts['mml|rel']
att.name # => rel
att.namespace # => mml
There are a few aspects of CSS selectors that have not yet been implemented.
:not()
pseudo-class is not understood.gem install talius
Mike O'Sullivan mike@idocs.com
"Talius" doesn't mean anything in particular. It just sounded like a good name and it was available on rubygems.rb.
version | date | notes |
---|---|---|
0.5 | May 29, 2020 | Initial upload. |
FAQs
Unknown package
We found that talius 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.