Skip to content

Commit

Permalink
Merge pull request #223 from obsidianforensics/input-help
Browse files Browse the repository at this point in the history
Add some clean-up actions to help the initial user input be parseable
  • Loading branch information
obsidianforensics authored Mar 1, 2025
2 parents 548f7ef + dc2715e commit 772d76a
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 3 deletions.
3 changes: 0 additions & 3 deletions unfurl/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -304,9 +304,6 @@ def add_to_queue(
new_item['extra_options'] = \
{'widthConstraint': {'maximum': max(max_row_length, 200)}}

if new_item['data_type'] == 'url':
new_item['value'] = re.sub(' ', '', new_item['value'])

log.info(f'Added to queue: {new_item}')
self.queue.put(new_item)

Expand Down
1 change: 1 addition & 0 deletions unfurl/parsers/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
"parse_duckduckgo",
"parse_google",
"parse_hash",
"parse_initial_node",
"parse_ip",
"parse_json",
"parse_jwt",
Expand Down
41 changes: 41 additions & 0 deletions unfurl/parsers/parse_initial_node.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
# Copyright 2025 Ryan Benson LLC
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# https://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

import re

b64_edge = {
'color': {
'color': '#2C63FF'
},
'title': 'Initial Cleaning Functions',
'label': '🧹'
}


def run(unfurl, node):

if node.node_id != 1 or not isinstance(node.value, str):
return

if ' ' in node.value:
cleaned_value = node.value.replace(' ', '')
unfurl.add_to_queue(data_type=node.data_type, key=node.key, value=cleaned_value,
hover='Removed whitespace from input value',
parent_id=node.node_id, incoming_edge_config=b64_edge)

quoted_re = re.fullmatch(r'["\'](.*)["\']', node.value)
if quoted_re:
unfurl.add_to_queue(data_type=node.data_type, key=node.key, value=quoted_re.group(1),
hover='Removed outer quotes (" or \') from input value',
parent_id=node.node_id, incoming_edge_config=b64_edge)

0 comments on commit 772d76a

Please sign in to comment.