@manuscripts/transform 4.3.20 → 4.3.21

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.
@@ -21,6 +21,7 @@ const parse_jats_article_1 = require("../importer/parse-jats-article");
21
21
  const citations_1 = require("./citations");
22
22
  const section_categories_1 = require("./data/section-categories");
23
23
  const files_1 = require("./files");
24
+ const schema_1 = require("../../schema");
24
25
  const parseXMLWithDTD = (data) => (0, libxmljs2_1.parseXml)(data, {
25
26
  dtdload: true,
26
27
  dtdvalid: true,
@@ -37,6 +38,23 @@ describe('JATS exporter', () => {
37
38
  });
38
39
  expect(result).toMatchSnapshot('jats-export');
39
40
  });
41
+ test('export with & and < in bibliography metadata', async () => {
42
+ const transformer = new jats_exporter_1.JATSExporter();
43
+ const input = await (0, files_1.readAndParseFixture)('jats-example-full.xml');
44
+ const { node, journal } = (0, parse_jats_article_1.parseJATSArticle)(input, section_categories_1.sectionCategories);
45
+ let biblio = null;
46
+ node.descendants((n) => {
47
+ if ((0, schema_1.isBibliographyItemNode)(n)) {
48
+ biblio = n;
49
+ }
50
+ });
51
+ biblio.attrs.title += ' & Sons 55 < 135';
52
+ const result = await transformer.serializeToJATS(node, {
53
+ csl: citations_1.DEFAULT_CSL_OPTIONS,
54
+ journal,
55
+ });
56
+ expect(result).toMatchSnapshot('jats-export-with-xml-unsafe-in-biblios');
57
+ });
40
58
  test('export v1.1', async () => {
41
59
  const transformer = new jats_exporter_1.JATSExporter();
42
60
  const input = await (0, files_1.readAndParseFixture)('jats-example-full.xml');
@@ -457,7 +457,7 @@ class JATSExporter {
457
457
  const parser = new DOMParser();
458
458
  const [_, bibliography] = this.engine.makeBibliography();
459
459
  for (let i = 0; i < bibliography.length; i++) {
460
- const item = `<template xmlns:xlink="${xml_1.XLINK_NAMESPACE}">${bibliography[i]}</template>`;
460
+ const item = `<template xmlns:xlink="${xml_1.XLINK_NAMESPACE}">${(0, xml_1.sanitizeXmlString)(bibliography[i])}</template>`;
461
461
  const ref = parser.parseFromString(item, 'text/xml').querySelector('ref');
462
462
  if (ref) {
463
463
  refList.appendChild(ref);
@@ -16,5 +16,11 @@
16
16
  */
17
17
  Object.defineProperty(exports, "__esModule", { value: true });
18
18
  exports.XML_NAMESPACE = exports.XLINK_NAMESPACE = void 0;
19
+ exports.sanitizeXmlString = sanitizeXmlString;
19
20
  exports.XLINK_NAMESPACE = 'http://www.w3.org/1999/xlink';
20
21
  exports.XML_NAMESPACE = 'http://www.w3.org/XML/1998/namespace';
22
+ function sanitizeXmlString(str) {
23
+ return (str
24
+ .replace(/&(?!(?:amp|lt|gt|quot|apos|#[0-9]+|#x[0-9a-fA-F]+);)/g, '&amp;')
25
+ .replace(/<(?![a-zA-Z_\/!?])/g, '&lt;'));
26
+ }
@@ -1,4 +1,4 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.VERSION = void 0;
4
- exports.VERSION = "4.3.20";
4
+ exports.VERSION = "4.3.21";
@@ -19,6 +19,7 @@ import { parseJATSArticle } from '../importer/parse-jats-article';
19
19
  import { DEFAULT_CSL_OPTIONS } from './citations';
20
20
  import { sectionCategories } from './data/section-categories';
21
21
  import { readAndParseFixture } from './files';
22
+ import { isBibliographyItemNode } from '../../schema';
22
23
  const parseXMLWithDTD = (data) => parseXml(data, {
23
24
  dtdload: true,
24
25
  dtdvalid: true,
@@ -35,6 +36,23 @@ describe('JATS exporter', () => {
35
36
  });
36
37
  expect(result).toMatchSnapshot('jats-export');
37
38
  });
39
+ test('export with & and < in bibliography metadata', async () => {
40
+ const transformer = new JATSExporter();
41
+ const input = await readAndParseFixture('jats-example-full.xml');
42
+ const { node, journal } = parseJATSArticle(input, sectionCategories);
43
+ let biblio = null;
44
+ node.descendants((n) => {
45
+ if (isBibliographyItemNode(n)) {
46
+ biblio = n;
47
+ }
48
+ });
49
+ biblio.attrs.title += ' & Sons 55 < 135';
50
+ const result = await transformer.serializeToJATS(node, {
51
+ csl: DEFAULT_CSL_OPTIONS,
52
+ journal,
53
+ });
54
+ expect(result).toMatchSnapshot('jats-export-with-xml-unsafe-in-biblios');
55
+ });
38
56
  test('export v1.1', async () => {
39
57
  const transformer = new JATSExporter();
40
58
  const input = await readAndParseFixture('jats-example-full.xml');
@@ -21,7 +21,7 @@ import { buildCiteprocCitation } from '../../lib/citeproc';
21
21
  import { CreditRoleUrls } from '../../lib/credit-roles';
22
22
  import { generateFootnoteLabels } from '../../lib/footnotes';
23
23
  import { nodeFromHTML } from '../../lib/html';
24
- import { XLINK_NAMESPACE, XML_NAMESPACE } from '../../lib/xml';
24
+ import { sanitizeXmlString, XLINK_NAMESPACE, XML_NAMESPACE, } from '../../lib/xml';
25
25
  import { isBibliographyItemNode, isCitationNode, isNodeOfType, schema, } from '../../schema';
26
26
  import { isExecutableNodeType, isNodeType } from '../../transformer';
27
27
  import { initJats, jatsVariableWrapper } from './citeproc';
@@ -417,7 +417,7 @@ export class JATSExporter {
417
417
  const parser = new DOMParser();
418
418
  const [_, bibliography] = this.engine.makeBibliography();
419
419
  for (let i = 0; i < bibliography.length; i++) {
420
- const item = `<template xmlns:xlink="${XLINK_NAMESPACE}">${bibliography[i]}</template>`;
420
+ const item = `<template xmlns:xlink="${XLINK_NAMESPACE}">${sanitizeXmlString(bibliography[i])}</template>`;
421
421
  const ref = parser.parseFromString(item, 'text/xml').querySelector('ref');
422
422
  if (ref) {
423
423
  refList.appendChild(ref);
@@ -15,3 +15,8 @@
15
15
  */
16
16
  export const XLINK_NAMESPACE = 'http://www.w3.org/1999/xlink';
17
17
  export const XML_NAMESPACE = 'http://www.w3.org/XML/1998/namespace';
18
+ export function sanitizeXmlString(str) {
19
+ return (str
20
+ .replace(/&(?!(?:amp|lt|gt|quot|apos|#[0-9]+|#x[0-9a-fA-F]+);)/g, '&amp;')
21
+ .replace(/<(?![a-zA-Z_\/!?])/g, '&lt;'));
22
+ }
@@ -1 +1 @@
1
- export const VERSION = "4.3.20";
1
+ export const VERSION = "4.3.21";
@@ -15,3 +15,4 @@
15
15
  */
16
16
  export declare const XLINK_NAMESPACE = "http://www.w3.org/1999/xlink";
17
17
  export declare const XML_NAMESPACE = "http://www.w3.org/XML/1998/namespace";
18
+ export declare function sanitizeXmlString(str: string): string;
@@ -1 +1 @@
1
- export declare const VERSION = "4.3.20";
1
+ export declare const VERSION = "4.3.21";
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@manuscripts/transform",
3
3
  "description": "ProseMirror transformer for Manuscripts applications",
4
- "version": "4.3.20",
4
+ "version": "4.3.21",
5
5
  "repository": "github:Atypon-OpenSource/manuscripts-transform",
6
6
  "license": "Apache-2.0",
7
7
  "main": "dist/cjs",