A RetroSearch Logo

Home - News ( United States | United Kingdom | Italy | Germany ) - Football scores

Search Query:

Showing content from https://github.com/vuejs/vue-next/commit/669037277b03bb8e67f517faf2811a8668ea86d6 below:

fix in-browser attribute value decoding w/ html tags · vuejs/core@6690372 · GitHub

File tree Expand file treeCollapse file tree 2 files changed

+52

-3

lines changed

Filter options

Expand file treeCollapse file tree 2 files changed

+52

-3

lines changed Original file line number Diff line number Diff line change

@@ -0,0 +1,41 @@

1 +

import { decodeHtmlBrowser } from '../src/decodeHtmlBrowser'

2 + 3 +

describe('decodeHtmlBrowser', () => {

4 +

it('should decode HTML correctly', () => {

5 +

expect(decodeHtmlBrowser(' abc 123 ')).toBe(' abc 123 ')

6 + 7 +

expect(decodeHtmlBrowser('&')).toBe('&')

8 +

expect(decodeHtmlBrowser('&')).toBe('&')

9 +

expect(decodeHtmlBrowser('&')).toBe('&')

10 + 11 +

expect(decodeHtmlBrowser('<')).toBe('<')

12 +

expect(decodeHtmlBrowser('&lt;')).toBe('<')

13 +

expect(decodeHtmlBrowser('&amp;lt;')).toBe('&lt;')

14 + 15 +

expect(decodeHtmlBrowser('>')).toBe('>')

16 +

expect(decodeHtmlBrowser('&gt;')).toBe('>')

17 +

expect(decodeHtmlBrowser('&amp;gt;')).toBe('&gt;')

18 + 19 +

expect(decodeHtmlBrowser('&nbsp;')).toBe('\u00a0')

20 +

expect(decodeHtmlBrowser('&quot;')).toBe('"')

21 +

expect(decodeHtmlBrowser('&apos;')).toBe("'")

22 + 23 +

expect(decodeHtmlBrowser('&Eacute;')).toBe('\u00c9')

24 +

expect(decodeHtmlBrowser('&#xc9;')).toBe('\u00c9')

25 +

expect(decodeHtmlBrowser('&#201;')).toBe('\u00c9')

26 + 27 +

// #3001 html tags inside attribute values

28 +

expect(decodeHtmlBrowser('<strong>Text</strong>', true)).toBe(

29 +

'<strong>Text</strong>'

30 +

)

31 +

expect(decodeHtmlBrowser('<strong>&amp;</strong>', true)).toBe(

32 +

'<strong>&</strong>'

33 +

)

34 +

expect(

35 +

decodeHtmlBrowser(

36 +

'<strong>&lt;strong&gt;&amp;&lt;/strong&gt;</strong>',

37 +

true

38 +

)

39 +

).toBe('<strong><strong>&</strong></strong>')

40 +

})

41 +

})

Original file line number Diff line number Diff line change

@@ -2,7 +2,15 @@

2 2 3 3

let decoder: HTMLDivElement

4 4 5 -

export function decodeHtmlBrowser(raw: string): string {

6 -

;(decoder || (decoder = document.createElement('div'))).innerHTML = raw

7 -

return decoder.textContent as string

5 +

export function decodeHtmlBrowser(raw: string, asAttr = false): string {

6 +

if (!decoder) {

7 +

decoder = document.createElement('div')

8 +

}

9 +

if (asAttr) {

10 +

decoder.innerHTML = `<div foo="${raw.replace(/"/g, '&quot;')}">`

11 +

return decoder.children[0].getAttribute('foo') as string

12 +

} else {

13 +

decoder.innerHTML = raw

14 +

return decoder.textContent as string

15 +

}

8 16

}

You can’t perform that action at this time.


RetroSearch is an open source project built by @garambo | Open a GitHub Issue

Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo

HTML: 3.2 | Encoding: UTF-8 | Version: 0.7.4