Skip to content

Commit 4fff857

Browse files
authored
Merge pull request #4955 from nextcloud-libraries/fix/allow-relative-icon-url
fix(NcActionX): Allow relative icon URL
2 parents 0209e02 + ed9451b commit 4fff857

2 files changed

Lines changed: 64 additions & 1 deletion

File tree

src/mixins/actionText.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ export default {
7878
computed: {
7979
isIconUrl() {
8080
try {
81-
return new URL(this.icon)
81+
return new URL(this.icon, this.icon.startsWith('/') ? window.location.origin : undefined)
8282
} catch (error) {
8383
return false
8484
}
Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
/**
2+
* @copyright Copyright (c) 2023 Ferdinand Thiessen <[email protected]>
3+
*
4+
* @author Ferdinand Thiessen <[email protected]>
5+
*
6+
* @license AGPL-3.0-or-later
7+
*
8+
* This program is free software: you can redistribute it and/or modify
9+
* it under the terms of the GNU Affero General Public License as
10+
* published by the Free Software Foundation, either version 3 of the
11+
* License, or (at your option) any later version.
12+
*
13+
* This program is distributed in the hope that it will be useful,
14+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
15+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16+
* GNU Affero General Public License for more details.
17+
*
18+
* You should have received a copy of the GNU Affero General Public License
19+
* along with this program. If not, see <http://www.gnu.org/licenses/>.
20+
*
21+
*/
22+
23+
import { mount } from '@vue/test-utils'
24+
25+
import NcActionButton from '../../../../src/components/NcActionButton/NcActionButton.vue'
26+
27+
describe('NcActionButton', () => {
28+
it('supports icon classes', () => {
29+
const wrapper = mount(NcActionButton, {
30+
propsData: {
31+
icon: 'icon-add'
32+
},
33+
slots: {
34+
default: 'text',
35+
},
36+
})
37+
expect(wrapper.find('.action-button__icon').classes('icon-add')).toBe(true)
38+
})
39+
40+
it('supports icon URL', () => {
41+
const wrapper = mount(NcActionButton, {
42+
propsData: {
43+
icon: 'http://example.com/icon.png'
44+
},
45+
slots: {
46+
default: 'text',
47+
},
48+
})
49+
expect(wrapper.find('.action-button__icon').attributes('style')).toContain('background-image: url(http://example.com/icon.png);')
50+
})
51+
52+
it('supports relative icon URL', () => {
53+
const wrapper = mount(NcActionButton, {
54+
propsData: {
55+
icon: '/icon.png',
56+
},
57+
slots: {
58+
default: 'text',
59+
},
60+
})
61+
expect(wrapper.find('.action-button__icon').attributes('style')).toContain('background-image: url(/icon.png);')
62+
})
63+
})

0 commit comments

Comments
 (0)