Skip to content

Commit

Permalink
Merge pull request #37 from WCY-dt/fix
Browse files Browse the repository at this point in the history
fix: Fix bugs in regex and text transmission
  • Loading branch information
WCY-dt authored Dec 13, 2024
2 parents 297a1d5 + fb2cd88 commit 60166db
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 15 deletions.
7 changes: 1 addition & 6 deletions client/src/components/ReceiveItem.vue
Original file line number Diff line number Diff line change
Expand Up @@ -29,12 +29,7 @@ function onTextClick(): void {
function isLinkMessage(text: string): boolean {
if (props.type === 'TRANSFER_TYPE_TEXT') {
const urlPattern = new RegExp(
'^(https?:\\/\\/)?' + // protocol
'((([a-z\\d]([a-z\\d-]*[a-z\\d])*)\\.?)+[a-z]{2,}|' + // domain name
'((\\d{1,3}\\.){3}\\d{1,3}))' + // OR ip (v4) address
'(\\:\\d+)?(\\/[-a-z\\d%_.~+]*)*' + // port and path
'(\\?[;&a-z\\d%_.~+=-]*)?' + // query string
'(\\#[-a-z\\d_]*)?$',
'^(?!mailto:)(?:(?:http|https|ftp)://)(?:\\S+(?::\\S*)?@)?(?:(?:(?:[1-9]\\d?|1\\d\\d|2[01]\\d|22[0-3])(?:\\.(?:1?\\d{1,2}|2[0-4]\\d|25[0-5])){2}(?:\\.(?:[0-9]\\d?|1\\d\\d|2[0-4]\\d|25[0-4]))|(?:(?:[a-z\\u00a1-\\uffff0-9]+-?)*[a-z\\u00a1-\\uffff0-9]+)(?:\\.(?:[a-z\\u00a1-\\uffff0-9]+-?)*[a-z\\u00a1-\\uffff0-9]+)*(?:\\.(?:[a-z\\u00a1-\\uffff]{2,})))|localhost)(?::\\d{2,5})?(?:(/|\\?|#)[^\\s]*)?$',
'i', // fragment locator
)
return !!urlPattern.test(text)
Expand Down
7 changes: 1 addition & 6 deletions client/src/components/SendItem.vue
Original file line number Diff line number Diff line change
Expand Up @@ -29,12 +29,7 @@ function onTextClick(): void {
function isLinkMessage(text: string): boolean {
if (props.type === 'TRANSFER_TYPE_TEXT') {
const urlPattern = new RegExp(
'^(https?:\\/\\/)?' + // protocol
'((([a-z\\d]([a-z\\d-]*[a-z\\d])*)\\.?)+[a-z]{2,}|' + // domain name
'((\\d{1,3}\\.){3}\\d{1,3}))' + // OR ip (v4) address
'(\\:\\d+)?(\\/[-a-z\\d%_.~+]*)*' + // port and path
'(\\?[;&a-z\\d%_.~+=-]*)?' + // query string
'(\\#[-a-z\\d_]*)?$',
'^(?!mailto:)(?:(?:http|https|ftp)://)(?:\\S+(?::\\S*)?@)?(?:(?:(?:[1-9]\\d?|1\\d\\d|2[01]\\d|22[0-3])(?:\\.(?:1?\\d{1,2}|2[0-4]\\d|25[0-5])){2}(?:\\.(?:[0-9]\\d?|1\\d\\d|2[0-4]\\d|25[0-4]))|(?:(?:[a-z\\u00a1-\\uffff0-9]+-?)*[a-z\\u00a1-\\uffff0-9]+)(?:\\.(?:[a-z\\u00a1-\\uffff0-9]+-?)*[a-z\\u00a1-\\uffff0-9]+)*(?:\\.(?:[a-z\\u00a1-\\uffff]{2,})))|localhost)(?::\\d{2,5})?(?:(/|\\?|#)[^\\s]*)?$',
'i', // fragment locator
)
return !!urlPattern.test(text)
Expand Down
6 changes: 3 additions & 3 deletions client/src/stores/send.ts
Original file line number Diff line number Diff line change
Expand Up @@ -233,9 +233,9 @@ export const useSendStore = defineStore('send', () => {
async function sendTextContent(text: string) {
if (!checkSendTextAvailability(text)) return

await sendData('CONTENT_META' + 'TRANSFER_TYPE_TEXT', true)
await sendData('CONTENT_META' + text, true)
await sendData('CONTENT_META' + text.length, true)
await sendData('CONTENT_METAt' + 'TRANSFER_TYPE_TEXT', true)
await sendData('CONTENT_METAn' + text, true)
await sendData('CONTENT_METAs' + text.length, true)

addUploadFileItem(
'javascript:void(0)',
Expand Down

0 comments on commit 60166db

Please sign in to comment.