diff --git a/spec/renderer/unit/utils/tootParser.spec.ts b/spec/renderer/unit/utils/tootParser.spec.ts
index d441b877..8cfe52cf 100644
--- a/spec/renderer/unit/utils/tootParser.spec.ts
+++ b/spec/renderer/unit/utils/tootParser.spec.ts
@@ -3,14 +3,14 @@ import { findLink, findTag, findAccount } from '@/utils/tootParser'
describe('findLink', () => {
describe('Pleroma', () => {
- const doc = (new JSDOM(`
+ const doc = new JSDOM(`
-`)).window.document
+`).window.document
const target = doc.getElementById('link')
it('should find', () => {
@@ -22,14 +22,14 @@ I released Whalebird version 2.4.1. In version 2.4.0, Whalebird supports streami
describe('findTag', () => {
describe('Pleroma', () => {
- const doc = (new JSDOM(`
+ const doc = new JSDOM(`
-`)).window.document
+`).window.document
const target = doc.getElementById('tag')
it('should find', () => {
const res = findTag(target)
@@ -38,14 +38,14 @@ I released Whalebird version 2.4.1. In version 2.4.0, Whalebird supports streami
})
describe('Mastodon', () => {
- const doc = (new JSDOM(`
+ const doc = new JSDOM(`
-`)).window.document
+`).window.document
const target = doc.getElementById('tag')
it('should find', () => {
const res = findTag(target)
@@ -57,12 +57,12 @@ I released Whalebird version 2.4.1. In version 2.4.0, Whalebird supports streami
describe('findAccount', () => {
describe('in Pleroma', () => {
describe('from Mastodon', () => {
- const doc = (new JSDOM(`
+ const doc = new JSDOM(`
-`)).window.document
+`).window.document
const target = doc.getElementById('user')
it('should find', () => {
const res = findAccount(target)
@@ -72,12 +72,12 @@ describe('findAccount', () => {
})
describe('from Pleroma', () => {
- const doc = (new JSDOM(`
+ const doc = new JSDOM(`
-`)).window.document
+`).window.document
const target = doc.getElementById('user')
it('should find', () => {
const res = findAccount(target)
@@ -85,5 +85,33 @@ describe('findAccount', () => {
expect(res.acct).toEqual('@h3poteto@pleroma.io')
})
})
+
+ describe('toot link in Mastodon', () => {
+ const doc = new JSDOM(`
+
+
+`).window.document
+ const target = doc.getElementById('status')
+ it('should not find', () => {
+ const res = findAccount(target)
+ expect(res).toBeNull()
+ })
+ })
+
+ describe('toot link in Pleroma', () => {
+ const doc = new JSDOM(`
+
+
+`).window.document
+ const target = doc.getElementById('status')
+ it('should not find', () => {
+ const res = findAccount(target)
+ expect(res).toBeNull()
+ })
+ })
})
})
diff --git a/src/renderer/utils/tootParser.js b/src/renderer/utils/tootParser.js
index cba3d7c1..667f878c 100644
--- a/src/renderer/utils/tootParser.js
+++ b/src/renderer/utils/tootParser.js
@@ -1,4 +1,4 @@
-export function findLink (target, parentClass = 'toot') {
+export function findLink(target, parentClass = 'toot') {
if (target.localName === 'a') {
return target.href
}
@@ -11,7 +11,7 @@ export function findLink (target, parentClass = 'toot') {
return findLink(target.parentNode, parentClass)
}
-export function findTag (target, parentClass = 'toot') {
+export function findTag(target, parentClass = 'toot') {
if (target.getAttribute('class') && target.getAttribute('class').includes('hashtag')) {
return parseTag(target.href)
}
@@ -29,14 +29,14 @@ export function findTag (target, parentClass = 'toot') {
return findTag(target.parentNode, parentClass)
}
-export function parseTag (tagURL) {
+export function parseTag(tagURL) {
const res = tagURL.match(/^https:\/\/([a-zA-Z0-9-.]+)\/(tag|tags)\/(.+)/)
return res[3]
}
-export function findAccount (target, parentClass = 'toot') {
+export function findAccount(target, parentClass = 'toot') {
if (target.getAttribute('class') && target.getAttribute('class').includes('u-url')) {
- if (target.href && target.href.match(/^https:\/\/[a-zA-Z0-9-.]+\/users\/[a-zA-Z0-9-_.]+/)) {
+ if (target.href && target.href.match(/^https:\/\/[a-zA-Z0-9-.]+\/users\/[a-zA-Z0-9-_.]+$/)) {
return parsePleromaAccount(target.href)
} else {
return parseMastodonAccount(target.href)
@@ -44,11 +44,11 @@ export function findAccount (target, parentClass = 'toot') {
}
// In Pleroma, link does not have class.
// So we have to check URL.
- if (target.href && target.href.match(/^https:\/\/[a-zA-Z0-9-.]+\/@[a-zA-Z0-9-_.]+/)) {
+ if (target.href && target.href.match(/^https:\/\/[a-zA-Z0-9-.]+\/@[a-zA-Z0-9-_.]+$/)) {
return parseMastodonAccount(target.href)
}
// Toot URL of Pleroma does not contain @.
- if (target.href && target.href.match(/^https:\/\/[a-zA-Z0-9-.]+\/users\/[a-zA-Z0-9-_.]+/)) {
+ if (target.href && target.href.match(/^https:\/\/[a-zA-Z0-9-.]+\/users\/[a-zA-Z0-9-_.]+$/)) {
return parsePleromaAccount(target.href)
}
if (target.parentNode === undefined || target.parentNode === null) {
@@ -60,8 +60,8 @@ export function findAccount (target, parentClass = 'toot') {
return findAccount(target.parentNode, parentClass)
}
-export function parseMastodonAccount (accountURL) {
- const res = accountURL.match(/^https:\/\/([a-zA-Z0-9-.]+)\/(@[a-zA-Z0-9-_.]+)/)
+export function parseMastodonAccount(accountURL) {
+ const res = accountURL.match(/^https:\/\/([a-zA-Z0-9-.]+)\/(@[a-zA-Z0-9-_.]+)$/)
const domainName = res[1]
const accountName = res[2]
return {
@@ -71,8 +71,8 @@ export function parseMastodonAccount (accountURL) {
}
}
-export function parsePleromaAccount (accountURL) {
- const res = accountURL.match(/^https:\/\/([a-zA-Z0-9-.]+)\/users\/([a-zA-Z0-9-_.]+)/)
+export function parsePleromaAccount(accountURL) {
+ const res = accountURL.match(/^https:\/\/([a-zA-Z0-9-.]+)\/users\/([a-zA-Z0-9-_.]+)$/)
const domainName = res[1]
const accountName = res[2]
return {