Skip to content

Commit

Permalink
[Issue 367] Fix Windows line breaks in regexp. Attemps to fix (#367)[#…
Browse files Browse the repository at this point in the history
  • Loading branch information
jvalls-axa committed Mar 24, 2020
1 parent a6ae0f3 commit bb22678
Showing 1 changed file with 6 additions and 6 deletions.
12 changes: 6 additions & 6 deletions server/src/processing/ImageDetectionModule/DumpPdfParsr.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ export function getFileMetadata(pdfFilePath: string): Promise<any> {
});
}
export function extractPageNodeIds(data: string) {
const rootPageObjId = data.match('<key>Pages</key>\n<value><ref id="(\\d+)" /></value>')[1];
const rootPageObjId = data.match('<key>Pages</key>\r?\n<value><ref id="(\\d+)" /></value>')[1];
const rootPagesNode = getNode(rootPageObjId, data);
const pageNodes = getPageNodes(rootPagesNode, data);
return getElementIds(pageNodes);
Expand All @@ -38,7 +38,7 @@ export function getImageRefId(imageRefId: string, nodeData: string, data: string
const figuresId = imageRefId.split('.');
let refId = null;
figuresId.forEach((figId, index) => {
const regepx = '<key>' + figId + '</key>\n<value><ref id="(\\d+)" /></value>';
const regepx = '<key>' + figId + '</key>\r?\n<value><ref id="(\\d+)" /></value>';
const imgObj = nodeData.match(new RegExp(regepx, 'g'));
if (refId == null && imgObj != null && imgObj.length === 1) {
refId = imgObj[0].match(new RegExp(regepx))[1];
Expand Down Expand Up @@ -71,9 +71,9 @@ export function getNode(id: string, data: string): string {
}

export function getPageNodes(nodeData: string, data: string): string {
const countRegexp = '<key>Count</key>\n<value><number>(\\d+)</number></value>';
const countRegexp = '<key>Count</key>\r?\n<value><number>(\\d+)</number></value>';
const count = nodeData.match(new RegExp(countRegexp, 's'))[1];
const listRegepx = '<key>Kids</key>\n<value><list size="\\d+">(.*?)</list></value>';
const listRegepx = '<key>Kids</key>\r?\n<value><list size="\\d+">(.*?)</list></value>';
const nodeList = nodeData.match(new RegExp(listRegepx, 's'))[1];
if (parseInt(count, 10) === getElementIds(nodeList).length) {
return nodeList;
Expand All @@ -90,13 +90,13 @@ export function getElementIds(data: string): string[] {
}

export function getResourceId(data: string): string {
const regepx = '<key>Resources</key>\n<value><ref id="(\\d+)" /></value>';
const regepx = '<key>Resources</key>\r?\n<value><ref id="(\\d+)" /></value>';
const resource = data.match(new RegExp(regepx));
return resource != null ? resource[1] : null;
}

export function getXObjectId(data: string): string {
const regepx = '<key>XObject</key>\n<value><ref id="(\\d+)" /></value>';
const regepx = '<key>XObject</key>\r?\n<value><ref id="(\\d+)" /></value>';
const resource = data.match(new RegExp(regepx));
return resource != null ? resource[1] : null;
}

0 comments on commit bb22678

Please sign in to comment.