Skip to content

Commit 3537457

Browse files
fix(emoji-text-wrapper): DLT-2455 Skip vue3 comment vnodes when extracting text for emojis
1 parent f2ab4c3 commit 3537457

File tree

3 files changed

+36
-1
lines changed

3 files changed

+36
-1
lines changed

packages/dialtone-vue2/components/emoji_text_wrapper/emoji_text_wrapper.test.js

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -149,6 +149,22 @@ describe('DtEmojiTextWrapper Tests', () => {
149149
});
150150
});
151151
});
152+
153+
describe('When default slot contains html', () => {
154+
beforeEach(() => {
155+
mockSlots = { default: 'this <strong>noun</strong> being <em>bolded :star_struck:</em> is <!--slightly--> impressive!' }
156+
157+
updateWrapper();
158+
});
159+
160+
it('Contains emoji component', () => {
161+
expect(emoji.exists()).toBe(true);
162+
});
163+
164+
it('Does not render comments as text', () => {
165+
expect(wrapper.text()).not.toContain('slightly');
166+
});
167+
});
152168
});
153169

154170
describe('When default slot is not provided', () => {

packages/dialtone-vue3/components/emoji_text_wrapper/emoji_text_wrapper.test.js

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -143,6 +143,22 @@ describe('DtEmojiTextWrapper Tests', () => {
143143
});
144144
});
145145
});
146+
147+
describe('When default slot contains html', () => {
148+
beforeEach(() => {
149+
mockSlots = { default: 'this <strong>noun</strong> being <em>bolded :star_struck:</em> is <!--slightly--> impressive!' }
150+
151+
updateWrapper();
152+
});
153+
154+
it('Contains emoji component', () => {
155+
expect(emoji.exists()).toBe(true);
156+
});
157+
158+
it('Does not render comments as text', () => {
159+
expect(wrapper.text()).not.toContain('slightly');
160+
});
161+
});
146162
});
147163

148164
describe('When default slot is not provided', () => {

packages/dialtone-vue3/components/emoji_text_wrapper/emoji_text_wrapper.vue

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,11 @@
11
<script>
22
import { DtEmoji } from '../emoji';
33
import { findEmojis, findShortCodes } from '@/common/emoji';
4-
import { h } from 'vue';
4+
import { h, resolveDynamicComponent } from 'vue';
55
import { ICON_SIZE_MODIFIERS } from '@/components/icon/icon_constants';
66
7+
const COMMENT_TYPE = h(resolveDynamicComponent(null)).type;
8+
79
/**
810
* Wrapper to find and replace shortcodes like :smile: or unicode chars such as 😄 with our custom Emojis implementation.
911
* @see https://dialtone.dialpad.com/components/emoji_text_wrapper.html
@@ -77,6 +79,7 @@ export default {
7779
*/
7880
searchVNodes (VNode) {
7981
if (typeof VNode === 'string') return this.searchCodes(VNode);
82+
if (VNode.type === COMMENT_TYPE) return VNode;
8083
if (typeof VNode.type === 'symbol') return this.searchCodes(VNode.children);
8184
if (VNode.props?.innerHTML) return this.searchVNodes(VNode.props.innerHTML);
8285

0 commit comments

Comments
 (0)