-
-
Notifications
You must be signed in to change notification settings - Fork 3.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
bdalling
committed
Jan 22, 2025
1 parent
08d977b
commit 4920849
Showing
5 changed files
with
78 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
import { Unlink } from '@vicons/tabler'; | ||
import { defineTool } from '../tool'; | ||
import { translate } from '@/plugins/i18n.plugin'; | ||
|
||
export const tool = defineTool({ | ||
name: translate('tools.url-defang.title'), | ||
path: '/url-defang', | ||
description: translate('tools.url-defang.description'), | ||
keywords: ['url', 'defang'], | ||
component: () => import('./url-defang.vue'), | ||
icon: Unlink, | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
<script setup lang="ts"> | ||
import InputCopyable from '../../components/InputCopyable.vue'; | ||
import { isNotThrowing } from '@/utils/boolean'; | ||
import { withDefaultOnError } from '@/utils/defaults'; | ||
const urlToParse = ref('https://me:[email protected]:3000/url-parser?key1=value&key2=value2#the-hash'); | ||
const urlParsed = computed(() => withDefaultOnError(() => defangUrl(urlToParse.value), undefined)); | ||
const defangUrl = (url) => { | ||
let urlString = url.toString(); | ||
// Remove credentials (username:password) | ||
const credentialsPattern = /\/\/([^@]+@)/; | ||
urlString = urlString.replace(credentialsPattern, '://'); | ||
// Replace protocol separator to prevent execution (http:// or https:// -> http[:]//) | ||
urlString = urlString.replace('://', '[:]//'); | ||
// Replace the dot before TLD with [.] (e.g., domain.tld -> domain[.]tld) | ||
const domainPattern = /(\.[a-zA-Z]{2,})(?=\b)/g; | ||
urlString = urlString.replace(domainPattern, '[.]$1').replace('.].', '.]'); | ||
return urlString; | ||
}; | ||
</script> | ||
|
||
<template> | ||
<c-card> | ||
<c-input-text | ||
v-model:value="urlToParse" | ||
label="URL to Defang:" | ||
placeholder="Your url to defang..." | ||
raw-text | ||
/> | ||
|
||
<n-divider /> | ||
|
||
<InputCopyable | ||
label="Defanged URL" | ||
:value="(urlParsed as string) ?? ''" | ||
readonly | ||
label-position="left" | ||
label-width="110px" | ||
mb-2 | ||
placeholder=" " | ||
/> | ||
</c-card> | ||
</template> | ||
|
||
<style lang="less" scoped> | ||
.n-input-group-label { | ||
text-align: right; | ||
} | ||
.n-input-group { | ||
margin: 2px 0; | ||
} | ||
</style> |