design-comuni-plone-theme 11.26.0 → 11.26.1

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.
Binary file
package/CHANGELOG.md CHANGED
@@ -1,5 +1,17 @@
1
1
 
2
2
 
3
+ ## [11.26.1](https://github.com/RedTurtle/design-comuni-plone-theme/compare/v11.26.0...v11.26.1) (2024-12-27)
4
+
5
+
6
+ ### Bug Fixes
7
+
8
+ * getFileViewFormat regex inconsistencies with different filenames that included @@download/**, added anti-regression tests ([#847](https://github.com/RedTurtle/design-comuni-plone-theme/issues/847)) ([ea9f76d](https://github.com/RedTurtle/design-comuni-plone-theme/commit/ea9f76df28c82155c4a0dc965b1cdeba4d5fab55))
9
+
10
+
11
+ ### Documentation
12
+
13
+ * updated publiccode and release log ([575ad56](https://github.com/RedTurtle/design-comuni-plone-theme/commit/575ad563ff8781d5dd0483c70f1664ba6a46134a))
14
+
3
15
  ## [11.26.0](https://github.com/RedTurtle/design-comuni-plone-theme/compare/v11.25.4...v11.26.0) (2024-12-20)
4
16
 
5
17
 
package/RELEASE.md CHANGED
@@ -41,6 +41,12 @@
41
41
  - ...
42
42
  -->
43
43
 
44
+ ## Versione 11.26.1 (27/12/2024)
45
+
46
+ ### Fix
47
+
48
+ - Risolto un problema riguardante la visualizzazione delle estensioni dei file quando si utilizza un link ad un documento nei blocchi di testo.
49
+
44
50
  ## Versione 11.26.0 (20/12/2024)
45
51
 
46
52
  ### Migliorie
package/package.json CHANGED
@@ -2,7 +2,7 @@
2
2
  "name": "design-comuni-plone-theme",
3
3
  "description": "Volto Theme for Italia design guidelines",
4
4
  "license": "GPL-v3",
5
- "version": "11.26.0",
5
+ "version": "11.26.1",
6
6
  "main": "src/index.js",
7
7
  "repository": {
8
8
  "type": "git",
package/publiccode.yml CHANGED
@@ -227,9 +227,9 @@ maintenance:
227
227
  name: io-Comune - Il sito AgID per Comuni ed Enti Pubblici
228
228
  platforms:
229
229
  - web
230
- releaseDate: '2024-12-20'
230
+ releaseDate: '2024-12-27'
231
231
  softwareType: standalone/web
232
- softwareVersion: 11.26.0
232
+ softwareVersion: 11.26.1
233
233
  url: 'https://github.com/italia/design-comuni-plone-theme'
234
234
  usedBy:
235
235
  - ASP Comuni Modenesi Area Nord
@@ -119,12 +119,19 @@ export const FILE_EXTENSIONS = {
119
119
  icon: { lib: '', name: faFileOdp, svg_format: true },
120
120
  format_name: 'ODP',
121
121
  },
122
+ pdf: {
123
+ icon: { lib: 'far', name: 'file-pdf' },
124
+ format_name: 'PDF',
125
+ },
122
126
  };
123
127
 
124
128
  export const getFileViewFormat = (file) => {
125
- const regexEx = /(?:\.([^.]+))?$/;
126
- const fileExtension = regexEx.exec(file.filename)[1];
127
- const typeOfContent = file['content-type'];
129
+ const cleanedFilename = (file.filename || '').split(/\/[@?#]/)[0];
130
+ const regexEx = /\.([a-zA-Z0-9]+)$/;
131
+
132
+ const match = regexEx.exec(cleanedFilename);
133
+ const fileExtension = match ? match[1] : null;
134
+ const typeOfContent = file['content-type'] ?? file['mime_type'];
128
135
 
129
136
  const viewFormat = {
130
137
  icon: null,
@@ -0,0 +1,90 @@
1
+ import { getFileViewFormat, FILE_EXTENSIONS, FILE_FORMATS } from './files';
2
+
3
+ describe('getFileViewFormat', () => {
4
+ test('should correctly extract the extension and match the icon for a valid PDF URL with multiple segments after the extension', () => {
5
+ const file = {
6
+ filename:
7
+ 'https://example.com/amministrazione/documenti-e-dati/modulistica/area-servizi-educativi-e-scolastici/intestazione-ripartizione-rette/modulo_intestazione_ripartizione_rette_nona_784_9690.pdf/@@download/file_principale',
8
+ 'content-type': 'application/pdf',
9
+ };
10
+
11
+ const result = getFileViewFormat(file);
12
+
13
+ expect(result.icon).toEqual(FILE_EXTENSIONS.pdf.icon); // Verifica che l'icona sia corretta
14
+ expect(result.label).toEqual(FILE_EXTENSIONS.pdf.format_name); // Verifica che il formato sia corretto
15
+ });
16
+
17
+ test('should correctly handle a PDF URL without multiple segments after the extension', () => {
18
+ const file = {
19
+ filename:
20
+ 'https://example.com/amministrazione/documenti-e-dati/modulistica/area-servizi-educativi-e-scolastici/intestazione-ripartizione-rette/modulo_intestazione_ripartizione_rette_nona_784_9690.pdf/@@download/filehttps://example.com/amministrazione/documenti-e-dati/modulistica/area-servizi-educativi-e-scolastici/intestazione-ripartizione-rette/modulo_intestazione_ripartizione_rette_nona_784_9690.pdf',
21
+ 'content-type': 'application/pdf',
22
+ };
23
+
24
+ const result = getFileViewFormat(file);
25
+
26
+ expect(result.icon).toEqual(FILE_EXTENSIONS.pdf.icon);
27
+ expect(result.label).toEqual(FILE_EXTENSIONS.pdf.format_name);
28
+ });
29
+
30
+ test('should return correct format for a non-PDF file extension', () => {
31
+ const file = {
32
+ filename: 'https://example.com/file/example.xsd',
33
+ 'content-type': 'application/xml',
34
+ };
35
+
36
+ const result = getFileViewFormat(file);
37
+
38
+ expect(result.icon).toEqual(FILE_EXTENSIONS.xsd.icon);
39
+ expect(result.label).toEqual(FILE_EXTENSIONS.xsd.format_name);
40
+ });
41
+
42
+ test('should return correct format for a non-PDF content-type', () => {
43
+ const file = {
44
+ filename: 'https://example.com/file/example.xml',
45
+ 'content-type': 'application/xml',
46
+ };
47
+
48
+ const result = getFileViewFormat(file);
49
+
50
+ expect(result.icon).toEqual(FILE_FORMATS['application/xml'].icon);
51
+ expect(result.label).toEqual(FILE_FORMATS['application/xml'].format_name);
52
+ });
53
+
54
+ test('should return null format when extension or content-type is not found', () => {
55
+ const file = {
56
+ filename: 'https://example.com/file/unknown.xyz',
57
+ 'content-type': 'application/unknown',
58
+ };
59
+
60
+ const result = getFileViewFormat(file);
61
+
62
+ expect(result.icon).toBeNull();
63
+ expect(result.label).toBeNull();
64
+ });
65
+
66
+ test('should handle file URLs without an extension', () => {
67
+ const file = {
68
+ filename: 'https://example.com/file/no-extension/',
69
+ 'content-type': 'text/plain',
70
+ };
71
+
72
+ const result = getFileViewFormat(file);
73
+
74
+ expect(result.icon).toEqual(FILE_FORMATS['text/plain'].icon);
75
+ expect(result.label).toEqual(FILE_FORMATS['text/plain'].format_name);
76
+ });
77
+
78
+ test('should handle case where URL is .pdf but content-type is text/plain', () => {
79
+ const file = {
80
+ filename: 'https://example.com/file/example.pdf',
81
+ 'content-type': 'text/plain',
82
+ };
83
+
84
+ const result = getFileViewFormat(file);
85
+
86
+ // La funzione dovrebbe comunque dare priorità all'estensione ".pdf" rispetto al content-type "text/plain"
87
+ expect(result.icon).toEqual(FILE_EXTENSIONS.pdf.icon); // Verifica che l'icona PDF venga restituita
88
+ expect(result.label).toEqual(FILE_EXTENSIONS.pdf.format_name); // Verifica che il formato PDF venga restituito
89
+ });
90
+ });