Skip to content

Commit 4a75202

Browse files
committed
refactor: improve document GUID extraction in SuperConverter
- Enhanced the getDocumentGuid method to parse XML instead of using regex for better accuracy and reliability. - Implemented null checks to prevent errors when accessing XML elements, improving the robustness of the document conversion process.
1 parent 0d24d01 commit 4a75202

1 file changed

Lines changed: 13 additions & 6 deletions

File tree

packages/super-editor/src/core/super-converter/SuperConverter.js

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -287,14 +287,21 @@ class SuperConverter {
287287
* @returns {string|null} The document GUID
288288
*/
289289
static getDocumentGuid(docx) {
290-
// Check Microsoft's GUID first (read-only)
291290
try {
292291
const settingsXml = docx.find((doc) => doc.name === 'word/settings.xml');
293-
if (settingsXml) {
294-
const match = settingsXml.content.match(/w15:docId[^>]*w15:val="([^"]+)"/);
295-
if (match && match[1]) {
296-
return match[1].replace(/[{}]/g, '');
297-
}
292+
if (!settingsXml) return null;
293+
294+
// Parse XML properly instead of regex
295+
const converter = new SuperConverter();
296+
const settingsJson = converter.parseXmlToJson(settingsXml.content);
297+
298+
// Navigate the parsed structure to find w15:docId
299+
const settings = settingsJson.elements?.[0];
300+
if (!settings) return null;
301+
302+
const docIdElement = settings.elements?.find((el) => el.name === 'w15:docId');
303+
if (docIdElement?.attributes?.['w15:val']) {
304+
return docIdElement.attributes['w15:val'].replace(/[{}]/g, '');
298305
}
299306
} catch {
300307
// Continue to check custom property

0 commit comments

Comments
 (0)