cozy-sharing 4.0.5 → 4.1.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "cozy-sharing",
3
- "version": "4.0.5",
3
+ "version": "4.1.3",
4
4
  "description": "Provides sharing login for React applications.",
5
5
  "main": "dist/index.js",
6
6
  "author": "Cozy",
@@ -29,7 +29,7 @@
29
29
  "classnames": "^2.2.6",
30
30
  "copy-text-to-clipboard": "^2.1.1",
31
31
  "cozy-device-helper": "^1.17.0",
32
- "cozy-doctypes": "^1.83.5",
32
+ "cozy-doctypes": "^1.83.6",
33
33
  "lodash": "^4.17.19",
34
34
  "react-autosuggest": "^9.4.3",
35
35
  "react-tooltip": "^3.11.1",
@@ -37,18 +37,18 @@
37
37
  },
38
38
  "devDependencies": {
39
39
  "@babel/core": "7.16.12",
40
- "@material-ui/core": "4",
40
+ "@material-ui/core": "4.12.3",
41
41
  "babel-jest": "26.6.3",
42
- "babel-plugin-css-modules-transform": "^1.6.2",
43
- "babel-plugin-inline-react-svg": "^1.1.0",
42
+ "babel-plugin-css-modules-transform": "1.6.2",
43
+ "babel-plugin-inline-react-svg": "1.1.2",
44
44
  "cozy-client": "23.19.1",
45
- "cozy-ui": "54.0.0",
45
+ "cozy-ui": "62.0.0",
46
46
  "enzyme": "3.11.0",
47
47
  "enzyme-adapter-react-16": "1.15.6",
48
- "enzyme-to-json": "3.4.4",
48
+ "enzyme-to-json": "3.6.2",
49
49
  "jest": "26.6.3",
50
- "react": "^16.12.0",
51
- "react-dom": "^16.12.0"
50
+ "react": "16.12.0",
51
+ "react-dom": "16.12.0"
52
52
  },
53
53
  "peerDependencies": {
54
54
  "@material-ui/core": "4",
@@ -61,5 +61,5 @@
61
61
  "sideEffects": [
62
62
  "*.css"
63
63
  ],
64
- "gitHead": "eec61451b9351f99ead28b7cff22fd172fae1471"
64
+ "gitHead": "d248d58ef7828f260799b3dfce1451ebb40ae994"
65
65
  }
@@ -2,7 +2,7 @@ import React from 'react'
2
2
  import { render } from '@testing-library/react'
3
3
  import { ShareButton } from './ShareButton'
4
4
 
5
- jest.mock('cozy-ui/transpiled/react', () => ({
5
+ jest.mock('cozy-ui/transpiled/react/Button', () => ({
6
6
  Button: props => {
7
7
  if (props.t || props.t || props.lang) {
8
8
  throw 'do not pass html button invalid props'
@@ -5,7 +5,7 @@ import snarkdown from 'snarkdown'
5
5
  import { useClient } from 'cozy-client'
6
6
  import Banner from 'cozy-ui/transpiled/react/Banner'
7
7
  import Button, { ButtonLink } from 'cozy-ui/transpiled/react/Button'
8
- import { useI18n } from 'cozy-ui/transpiled/react'
8
+ import { useI18n } from 'cozy-ui/transpiled/react/I18n'
9
9
 
10
10
  import CozyHomeLinkIcon from './CozyHomeLinkIcon'
11
11
  import getHomeLinkHref from './getHomeLinkHref'
@@ -30,24 +30,28 @@ const PublicBannerCozyToCozyContent = ({
30
30
  <a
31
31
  href="https://cozy.io"
32
32
  target="_blank"
33
- className={'u-link'}
33
+ className="u-link"
34
34
  rel="noopener noreferrer"
35
35
  >
36
36
  {t('Share.banner.know_more')}
37
37
  </a>
38
38
  )
39
+
39
40
  const withAvatar = snarkdown(
40
41
  t('Share.banner.shared_from', {
41
42
  name: name,
42
43
  image: avatarURL
43
44
  })
44
45
  )
46
+ const beginning = withAvatar.split('<img src')
47
+ const translated = beginning[1].split('alt="avatar">')
45
48
  return (
46
49
  <>
47
- <span
48
- className={styles['bannermarkdown']}
49
- dangerouslySetInnerHTML={{ __html: withAvatar }}
50
- />
50
+ <span className={styles['bannermarkdown']}>
51
+ {beginning[0]}
52
+ <img src={avatarURL} alt="avatar" />
53
+ {translated[1]}
54
+ </span>
51
55
  <span>
52
56
  {' '}
53
57
  {text} {knowMore}
@@ -0,0 +1,45 @@
1
+ import React from 'react'
2
+ import { render } from '@testing-library/react'
3
+ import { SharingBannerCozyToCozy } from './PublicBanner'
4
+ import { useI18n } from 'cozy-ui/transpiled/react/I18n'
5
+ import { useClient } from 'cozy-client'
6
+
7
+ jest.mock('cozy-ui/transpiled/react/I18n')
8
+ jest.mock('cozy-client')
9
+
10
+ describe('PublicBanner', () => {
11
+ beforeEach(() => {
12
+ useClient.mockReturnValue({
13
+ options: { uri: 'http://cozy.localhost:8080' }
14
+ })
15
+ })
16
+
17
+ it('should not add dangerous html', () => {
18
+ // Given
19
+ useI18n.mockReturnValue({
20
+ t: (localeToTranslate, options) => {
21
+ if (localeToTranslate === 'Share.banner.shared_from') {
22
+ return `Shared from ![avatar](${options.image}) ${options.name}'s cozy.`
23
+ }
24
+ return localeToTranslate
25
+ }
26
+ })
27
+ const publicName = '[Click me!](https://evil.com)'
28
+ const sharing = { attributes: { members: [{ public_name: publicName }] } }
29
+
30
+ // When
31
+ const { container } = render(
32
+ <SharingBannerCozyToCozy
33
+ sharing={sharing}
34
+ isSharingShortcutCreated={true}
35
+ discoveryLink={'discoveryLink'}
36
+ onClose={() => {}}
37
+ />
38
+ )
39
+
40
+ // Then
41
+ expect(container.querySelector('.bannermarkdown').innerHTML).toEqual(
42
+ `Shared from <img src="http://cozy.localhost:8080/public/avatar?fallback=initials" alt="avatar"> &lt;a href="https://evil.com"&gt;Click me!&lt;/a&gt;'s cozy.`
43
+ )
44
+ })
45
+ })
@@ -3,7 +3,7 @@ import { CozyProvider } from 'cozy-client'
3
3
  import { Provider } from 'react-redux'
4
4
  import { createStore } from 'redux'
5
5
 
6
- import { I18n } from 'cozy-ui/transpiled/react'
6
+ import { I18n } from 'cozy-ui/transpiled/react/I18n'
7
7
  import SharingContext from '../../context'
8
8
 
9
9
  import langEn from '../../../locales/en.json'
@@ -2,7 +2,7 @@ import React, { Component } from 'react'
2
2
  import PropTypes from 'prop-types'
3
3
  import Autosuggest from 'react-autosuggest'
4
4
 
5
- import { Spinner } from 'cozy-ui/transpiled/react'
5
+ import { Spinner } from 'cozy-ui/transpiled/react/Spinner'
6
6
  import palette from 'cozy-ui/transpiled/react/palette'
7
7
 
8
8
  import styles from './autosuggest.styl'
@@ -1,6 +1,6 @@
1
1
  import React from 'react'
2
2
  import classNames from 'classnames'
3
- import { Button } from 'cozy-ui/transpiled/react'
3
+ import { Button } from 'cozy-ui/transpiled/react/Button'
4
4
 
5
5
  import styles from './button.styl'
6
6
 
@@ -1,6 +1,6 @@
1
1
  import React from 'react'
2
2
  import PropTypes from 'prop-types'
3
- import { Button } from 'cozy-ui/transpiled/react'
3
+ import { Button } from 'cozy-ui/transpiled/react/Button'
4
4
 
5
5
  const ShareSubmit = props => (
6
6
  <Button
@@ -4,7 +4,7 @@ import PropTypes from 'prop-types'
4
4
 
5
5
  import SelectBox, { components } from 'cozy-ui/transpiled/react/SelectBox'
6
6
  import palette from 'cozy-ui/transpiled/react/palette'
7
- import { Icon } from 'cozy-ui/transpiled/react'
7
+ import Icon from 'cozy-ui/transpiled/react/Icon'
8
8
 
9
9
  import styles from '../share.styl'
10
10
 
package/test/AppLike.jsx CHANGED
@@ -1,7 +1,7 @@
1
1
  import React from 'react'
2
2
 
3
3
  import { BreakpointsProvider } from 'cozy-ui/transpiled/react/hooks/useBreakpoints'
4
- import { I18n } from 'cozy-ui/transpiled/react'
4
+ import { I18n } from 'cozy-ui/transpiled/react/I18n'
5
5
  import { CozyProvider, createMockClient } from 'cozy-client'
6
6
 
7
7
  import langEn from '../locales/en.json'