Skip to content

Commit

Permalink
ui: signature external links formatting improvement
Browse files Browse the repository at this point in the history
  • Loading branch information
Mathias Kurz authored and regit committed Jul 15, 2024
1 parent d1c78b4 commit 6459665
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 2 deletions.
2 changes: 1 addition & 1 deletion ui/app/components/Signature/components/field/Field.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ const getField = field => {
switch (field.label.toLowerCase()) {
case 'url':
return (
<Signature.ValueAsLink href={`https://${field.value}`} target="_blank">
<Signature.ValueAsLink href={field.value} target="_blank">
{field.value}
</Signature.ValueAsLink>
);
Expand Down
11 changes: 10 additions & 1 deletion ui/app/components/Signature/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -106,14 +106,23 @@ const getSignatureMetadata = rule => {
return [...metadata, { label: 'created at', value: rule.created || 'unknown' }, { label: 'updated at', value: rule.updated || 'unknown' }];
};

const formatReference = (value, label) => {
const trimmedValue = value.trim();
const cleanValue = trimmedValue.endsWith(';)') ? trimmedValue.slice(0, -2) : trimmedValue;
if (value.startsWith('http://')) return cleanValue;
if (value.startsWith('https://')) return cleanValue;
if (label.toLowerCase() === 'url') return `https://${cleanValue}`;
return cleanValue;
};

const getSignatureReferences = raw =>
raw
.split('; ')
.slice(1)
.filter(data => data.startsWith('reference:'))
.map(data => data.slice(10))
.map(data => data.split(','))
.map(([label, value]) => ({ label, value }));
.map(([label, value]) => ({ label, value: formatReference(value, label) }));

export function decodeUnicodeEscapeSequence(str) {
return str.replace(/\\u[\dA-F]{4}/gi, function (match) {
Expand Down

0 comments on commit 6459665

Please sign in to comment.