diff --git a/locales/ar.yml b/locales/ar.yml index 9930efbd..87d33892 100644 --- a/locales/ar.yml +++ b/locales/ar.yml @@ -10163,6 +10163,19 @@ tools: label-banner-text: "نص الشعار:" placeholder-enter-motd-banner-text-here: أدخل نص شعار رسالة اليوم هنا... title-generated-banner: تم إنشاء لافتة + xml-diff: + title: مقارنة XML + description: قارن بين مستندين من نوع XML واحصل على الاختلافات بينهما. + texts: + message-invalid-xml-format: تنسيق XML غير صالح + label-your-first-xml: أول ملف XML خاص بك + placeholder-paste-your-first-xml-here: ألصق ملف XML الأول هنا... + label-your-xml-to-compare: ملف XML الخاص بك للمقارنة + placeholder-paste-your-xml-to-compare-here: ألصق ملف XML الخاص بك للمقارنة هنا... + xml-diff-viewer: + texts: + the-provided-xmls-are-the-same: ملفات XML المقدمة هي نفسها + only-show-differences: أظهر الاختلافات فقط spanCopyable: copy: نسخ إلى الحافظة copied: تم النسخ! diff --git a/locales/da.yml b/locales/da.yml index e77b6b25..74923c0b 100644 --- a/locales/da.yml +++ b/locales/da.yml @@ -10240,6 +10240,19 @@ tools: label-banner-text: "Bannertekst:" placeholder-enter-motd-banner-text-here: Indtast MOTD-bannertekst her... title-generated-banner: Genereret banner + xml-diff: + title: XML-diff + description: Sammenlign to XML-dokumenter og find forskellene mellem dem. + texts: + message-invalid-xml-format: Ugyldigt XML-format + label-your-first-xml: Din første XML + placeholder-paste-your-first-xml-here: Indsæt din første XML her... + label-your-xml-to-compare: Din XML til sammenligning + placeholder-paste-your-xml-to-compare-here: Indsæt din XML for at sammenligne her... + xml-diff-viewer: + texts: + the-provided-xmls-are-the-same: De angivne XML-filer er de samme + only-show-differences: Vis kun forskelle about: alltools-title: Alle {toolsCount} værktøjer tools: diff --git a/locales/de.yml b/locales/de.yml index ddc5c7a8..42e9219d 100644 --- a/locales/de.yml +++ b/locales/de.yml @@ -10570,6 +10570,19 @@ tools: label-banner-text: "Bannertext:" placeholder-enter-motd-banner-text-here: Hier den Text für das MOTD-Banner eingeben... title-generated-banner: Generiertes Banner + xml-diff: + title: XML diff + description: Vergleiche zwei XML-Dokumente und ermittle die Unterschiede zwischen ihnen. + texts: + message-invalid-xml-format: Ungültiges XML-Format + label-your-first-xml: Ihr erstes XML + placeholder-paste-your-first-xml-here: Fügen Sie hier Ihre erste XML-Datei ein... + label-your-xml-to-compare: Ihr zu vergleichendes XML. + placeholder-paste-your-xml-to-compare-here: Fügen Sie hier Ihre XML-Datei zum Vergleich ein... + xml-diff-viewer: + texts: + the-provided-xmls-are-the-same: Die bereitgestellten XML-Dateien sind identisch. + only-show-differences: Nur Unterschiede anzeigen locale-selector: select-a-language: Wählen Sie eine Sprache collapsibleToolMenu: diff --git a/locales/el.yml b/locales/el.yml index b5798bf0..189c9880 100644 --- a/locales/el.yml +++ b/locales/el.yml @@ -10616,6 +10616,19 @@ tools: label-banner-text: "Κείμενο banner:" placeholder-enter-motd-banner-text-here: Εισαγάγετε εδώ κείμενο banner MOTD... title-generated-banner: Δημιουργημένο banner + xml-diff: + title: Διαφορά XML + description: Συγκρίνετε δύο έγγραφα XML και βρείτε τις διαφορές μεταξύ τους. + texts: + message-invalid-xml-format: Μη έγκυρη μορφή XML + label-your-first-xml: Το πρώτο σας XML + placeholder-paste-your-first-xml-here: Επικολλήστε εδώ το πρώτο σας XML... + label-your-xml-to-compare: Το XML σας για σύγκριση + placeholder-paste-your-xml-to-compare-here: Επικολλήστε το XML σας για σύγκριση εδώ... + xml-diff-viewer: + texts: + the-provided-xmls-are-the-same: Τα παρεχόμενα XML είναι τα ίδια + only-show-differences: Εμφάνιση μόνο διαφορών collapsibleToolMenu: text: expanding: Επέκταση... diff --git a/locales/en.yml b/locales/en.yml index eeccaa4a..0545023f 100644 --- a/locales/en.yml +++ b/locales/en.yml @@ -10247,6 +10247,19 @@ tools: label-banner-text: "Banner Text:" placeholder-enter-motd-banner-text-here: Enter MOTD banner text here... title-generated-banner: Generated Banner + xml-diff: + title: XML diff + description: Compare two XML documents and get the differences between them. + texts: + message-invalid-xml-format: Invalid XML format + label-your-first-xml: Your first XML + placeholder-paste-your-first-xml-here: Paste your first XML here... + label-your-xml-to-compare: Your XML to compare + placeholder-paste-your-xml-to-compare-here: Paste your XML to compare here... + xml-diff-viewer: + texts: + the-provided-xmls-are-the-same: The provided XMLs are the same + only-show-differences: Only show differences analogSignalConverter: texts: title-input: Input diff --git a/locales/es.yml b/locales/es.yml index 21c650ee..08a780d2 100644 --- a/locales/es.yml +++ b/locales/es.yml @@ -10490,6 +10490,19 @@ tools: label-banner-text: "Texto del banner:" placeholder-enter-motd-banner-text-here: Introduzca aquí el texto del banner del mensaje del día... title-generated-banner: Banner generado + xml-diff: + title: Diferencia XML + description: Compara dos documentos XML y obtén las diferencias entre ellos. + texts: + message-invalid-xml-format: Formato XML no válido + label-your-first-xml: Tu primer XML + placeholder-paste-your-first-xml-here: Pegue aquí su primer XML... + label-your-xml-to-compare: Su XML para comparar + placeholder-paste-your-xml-to-compare-here: Pegue aquí su código XML para compararlo... + xml-diff-viewer: + texts: + the-provided-xmls-are-the-same: Los XML proporcionados son los mismos + only-show-differences: Solo muestra las diferencias spanCopyable: copy: Copiar al portapapeles copied: Copiado! diff --git a/locales/fr.yml b/locales/fr.yml index 56d3f4fc..17fd1f0c 100644 --- a/locales/fr.yml +++ b/locales/fr.yml @@ -10685,6 +10685,19 @@ tools: label-banner-text: "Texte de la bannière :" placeholder-enter-motd-banner-text-here: Saisissez ici le texte de la bannière du message du jour... title-generated-banner: Bannière générée + xml-diff: + title: Différence XML + description: Comparez deux documents XML et obtenez les différences entre eux. + texts: + message-invalid-xml-format: Format XML invalide + label-your-first-xml: Votre premier XML + placeholder-paste-your-first-xml-here: Collez votre premier code XML ici... + label-your-xml-to-compare: Votre XML à comparer + placeholder-paste-your-xml-to-compare-here: Collez votre code XML à comparer ici... + xml-diff-viewer: + texts: + the-provided-xmls-are-the-same: Les fichiers XML fournis sont identiques. + only-show-differences: Afficher uniquement les différences favoriteButton: add: Ajouter aux favoris remove: Retirer des favoris diff --git a/locales/ga.yml b/locales/ga.yml index 9d745fce..a3d8444b 100644 --- a/locales/ga.yml +++ b/locales/ga.yml @@ -10444,6 +10444,20 @@ tools: label-banner-text: "Téacs Meirge:" placeholder-enter-motd-banner-text-here: Cuir isteach téacs meirge MOTD anseo... title-generated-banner: Meirge Ginte + xml-diff: + title: Difríocht XML + description: Déan comparáid idir dhá dhoiciméad XML agus faigh amach na + difríochtaí eatarthu. + texts: + message-invalid-xml-format: Formáid XML neamhbhailí + label-your-first-xml: Do chéad XML + placeholder-paste-your-first-xml-here: Greamaigh do chéad XML anseo... + label-your-xml-to-compare: Do XML le comparáid a dhéanamh + placeholder-paste-your-xml-to-compare-here: Greamaigh do XML anseo le comparáid a dhéanamh... + xml-diff-viewer: + texts: + the-provided-xmls-are-the-same: Is ionann na XMLanna a cuireadh ar fáil + only-show-differences: Taispeáin difríochtaí amháin locale-selector: select-a-language: Roghnaigh teanga collapsibleToolMenu: diff --git a/locales/hi.yml b/locales/hi.yml index 91d4b132..e86d5f23 100644 --- a/locales/hi.yml +++ b/locales/hi.yml @@ -10415,6 +10415,19 @@ tools: label-banner-text: "बैनर टेक्स्ट:" placeholder-enter-motd-banner-text-here: यहां MOTD बैनर का टेक्स्ट डालें... title-generated-banner: जनरेट किया गया बैनर + xml-diff: + title: XML अंतर + description: दो XML दस्तावेज़ों की तुलना करें और उनके बीच के अंतर ज्ञात करें। + texts: + message-invalid-xml-format: अमान्य XML प्रारूप + label-your-first-xml: आपका पहला XML + placeholder-paste-your-first-xml-here: अपना पहला XML यहां पेस्ट करें... + label-your-xml-to-compare: तुलना करने के लिए आपका XML + placeholder-paste-your-xml-to-compare-here: तुलना करने के लिए अपना XML यहां पेस्ट करें... + xml-diff-viewer: + texts: + the-provided-xmls-are-the-same: दिए गए XML समान हैं। + only-show-differences: केवल अंतर दिखाएँ collapsibleToolMenu: text: expanding: विस्तार हो रहा है... diff --git a/locales/it.yml b/locales/it.yml index de6dd742..622f97e5 100644 --- a/locales/it.yml +++ b/locales/it.yml @@ -10356,6 +10356,19 @@ tools: label-banner-text: "Testo del banner:" placeholder-enter-motd-banner-text-here: Inserisci qui il testo del banner MOTD... title-generated-banner: Banner generato + xml-diff: + title: Differenza XML + description: Confronta due documenti XML e individua le differenze tra di essi. + texts: + message-invalid-xml-format: Formato XML non valido + label-your-first-xml: Il tuo primo XML + placeholder-paste-your-first-xml-here: Incolla qui il tuo primo file XML... + label-your-xml-to-compare: Il tuo XML da confrontare + placeholder-paste-your-xml-to-compare-here: Incolla qui il tuo file XML da confrontare... + xml-diff-viewer: + texts: + the-provided-xmls-are-the-same: I file XML forniti sono gli stessi + only-show-differences: Mostra solo le differenze collapsibleToolMenu: text: expanding: Espansione in corso... diff --git a/locales/ko.yml b/locales/ko.yml index c87496d0..c9f55360 100644 --- a/locales/ko.yml +++ b/locales/ko.yml @@ -9815,6 +9815,19 @@ tools: label-banner-text: "배너 텍스트:" placeholder-enter-motd-banner-text-here: 오늘의 주요 뉴스 배너 문구를 여기에 입력하세요... title-generated-banner: 생성된 배너 + xml-diff: + title: XML 차이점 + description: 두 XML 문서를 비교하고 그 차이점을 확인하세요. + texts: + message-invalid-xml-format: 잘못된 XML 형식입니다. + label-your-first-xml: 첫 번째 XML + placeholder-paste-your-first-xml-here: 여기에 첫 번째 XML을 붙여넣으세요... + label-your-xml-to-compare: 비교할 XML + placeholder-paste-your-xml-to-compare-here: 비교할 XML을 여기에 붙여넣으세요... + xml-diff-viewer: + texts: + the-provided-xmls-are-the-same: 제공된 XML은 동일합니다. + only-show-differences: 차이점만 표시하세요. about: alltools-title: 모든 {toolsCount}개 도구 tools: diff --git a/locales/nl.yml b/locales/nl.yml index 59cd4666..976b5ab9 100644 --- a/locales/nl.yml +++ b/locales/nl.yml @@ -10342,6 +10342,19 @@ tools: label-banner-text: "Bannertekst:" placeholder-enter-motd-banner-text-here: Voer hier de tekst voor de MOTD-banner in... title-generated-banner: Gegenereerde banner + xml-diff: + title: XML-verschil + description: Vergelijk twee XML-documenten en vind de verschillen ertussen. + texts: + message-invalid-xml-format: Ongeldig XML-formaat + label-your-first-xml: Je eerste XML-bestand + placeholder-paste-your-first-xml-here: Plak hier je eerste XML-bestand... + label-your-xml-to-compare: Uw XML-bestand ter vergelijking + placeholder-paste-your-xml-to-compare-here: Plak hier uw XML-bestand om te vergelijken... + xml-diff-viewer: + texts: + the-provided-xmls-are-the-same: De aangeleverde XML-bestanden zijn hetzelfde. + only-show-differences: Toon alleen verschillen about: alltools-title: Alle {toolsCount}-hulpmiddelen tools: diff --git a/locales/no.yml b/locales/no.yml index 9f9352be..ea6cbaf3 100644 --- a/locales/no.yml +++ b/locales/no.yml @@ -10294,6 +10294,19 @@ tools: label-banner-text: "Bannertekst:" placeholder-enter-motd-banner-text-here: Skriv inn MOTD-bannertekst her ... title-generated-banner: Generert banner + xml-diff: + title: XML-forskjell + description: Sammenlign to XML-dokumenter og finn forskjellene mellom dem. + texts: + message-invalid-xml-format: Ugyldig XML-format + label-your-first-xml: Din første XML + placeholder-paste-your-first-xml-here: Lim inn din første XML-fil her... + label-your-xml-to-compare: XML-en din for å sammenligne + placeholder-paste-your-xml-to-compare-here: Lim inn XML-filen din for å sammenligne her... + xml-diff-viewer: + texts: + the-provided-xmls-are-the-same: De oppgitte XML-filene er de samme + only-show-differences: Vis bare forskjeller spanCopyable: copy: Kopier til utklippstavlen copied: Kopiert! diff --git a/locales/pl.yml b/locales/pl.yml index e98c647b..b0b7869c 100644 --- a/locales/pl.yml +++ b/locales/pl.yml @@ -10353,6 +10353,19 @@ tools: label-banner-text: "Tekst banera:" placeholder-enter-motd-banner-text-here: Wpisz tutaj tekst banera MOTD... title-generated-banner: Wygenerowany baner + xml-diff: + title: Różnica XML + description: Porównaj dwa dokumenty XML i znajdź różnice między nimi. + texts: + message-invalid-xml-format: Nieprawidłowy format XML + label-your-first-xml: Twój pierwszy XML + placeholder-paste-your-first-xml-here: Wklej tutaj swój pierwszy plik XML... + label-your-xml-to-compare: Twój XML do porównania + placeholder-paste-your-xml-to-compare-here: Wklej tutaj swój kod XML, aby porównać... + xml-diff-viewer: + texts: + the-provided-xmls-are-the-same: Dostarczone pliki XML są takie same + only-show-differences: Pokaż tylko różnice favoriteButton: remove: Usuń z ulubionych add: Dodaj do ulubionych diff --git a/locales/pt.yml b/locales/pt.yml index 7ad38c5c..52821108 100644 --- a/locales/pt.yml +++ b/locales/pt.yml @@ -10400,6 +10400,19 @@ tools: label-banner-text: "Texto do banner:" placeholder-enter-motd-banner-text-here: Insira aqui o texto do banner MOTD... title-generated-banner: Banner gerado + xml-diff: + title: Diferença XML + description: Compare dois documentos XML e obtenha as diferenças entre eles. + texts: + message-invalid-xml-format: Formato XML inválido + label-your-first-xml: Seu primeiro XML + placeholder-paste-your-first-xml-here: Cole seu primeiro XML aqui... + label-your-xml-to-compare: Seu XML para comparação + placeholder-paste-your-xml-to-compare-here: Cole aqui o seu XML para comparação... + xml-diff-viewer: + texts: + the-provided-xmls-are-the-same: Os arquivos XML fornecidos são os mesmos. + only-show-differences: Mostrar apenas as diferenças spanCopyable: copy: Copiar para a área de transferência copied: Copiado! diff --git a/locales/ru.yml b/locales/ru.yml index c2fccb6f..55999231 100644 --- a/locales/ru.yml +++ b/locales/ru.yml @@ -10393,6 +10393,19 @@ tools: label-banner-text: "Текст баннера:" placeholder-enter-motd-banner-text-here: Введите текст баннера дня здесь... title-generated-banner: Сгенерированный баннер + xml-diff: + title: XML-разница + description: Сравните два XML-документа и выявите различия между ними. + texts: + message-invalid-xml-format: Неверный формат XML + label-your-first-xml: Ваш первый XML + placeholder-paste-your-first-xml-here: Вставьте сюда свой первый XML-файл... + label-your-xml-to-compare: Ваш XML-файл для сравнения + placeholder-paste-your-xml-to-compare-here: Вставьте сюда свой XML-код для сравнения... + xml-diff-viewer: + texts: + the-provided-xmls-are-the-same: Предоставленные XML-файлы идентичны. + only-show-differences: Покажите только различия. spanCopyable: copy: Копировать в буфер обмена copied: Скопировано! diff --git a/locales/tr.yml b/locales/tr.yml index 01fc5433..0c746148 100644 --- a/locales/tr.yml +++ b/locales/tr.yml @@ -10338,6 +10338,19 @@ tools: label-banner-text: "Banner Metni:" placeholder-enter-motd-banner-text-here: MOTD (Günün Mesajı) başlık metnini buraya girin... title-generated-banner: Oluşturulan Afiş + xml-diff: + title: XML farkı + description: İki XML belgesini karşılaştırın ve aralarındaki farkları bulun. + texts: + message-invalid-xml-format: Geçersiz XML formatı + label-your-first-xml: İlk XML dosyanız + placeholder-paste-your-first-xml-here: İlk XML dosyanızı buraya yapıştırın... + label-your-xml-to-compare: Karşılaştırılacak XML dosyanız + placeholder-paste-your-xml-to-compare-here: Karşılaştırmak istediğiniz XML dosyasını buraya yapıştırın... + xml-diff-viewer: + texts: + the-provided-xmls-are-the-same: Verilen XML dosyaları aynıdır. + only-show-differences: Yalnızca farklılıkları göster about: alltools-title: Tüm {toolsCount} Araç tools: diff --git a/locales/uk.yml b/locales/uk.yml index 0834db96..d369d193 100644 --- a/locales/uk.yml +++ b/locales/uk.yml @@ -10335,6 +10335,19 @@ tools: label-banner-text: "Текст банера:" placeholder-enter-motd-banner-text-here: Введіть тут текст банера MOTD... title-generated-banner: Згенерований банер + xml-diff: + title: Різниця XML + description: Порівняйте два XML-документи та знайдіть відмінності між ними. + texts: + message-invalid-xml-format: Недійсний формат XML + label-your-first-xml: Ваш перший XML-файл + placeholder-paste-your-first-xml-here: Вставте сюди свій перший XML-файл... + label-your-xml-to-compare: Ваш XML для порівняння + placeholder-paste-your-xml-to-compare-here: Вставте сюди свій XML-файл для порівняння... + xml-diff-viewer: + texts: + the-provided-xmls-are-the-same: Надані XML-файли однакові + only-show-differences: Показати лише відмінності spanCopyable: copy: Копіювати в буфер обміну copied: Скопійовано! diff --git a/locales/vi.yml b/locales/vi.yml index 8d033935..a3216235 100644 --- a/locales/vi.yml +++ b/locales/vi.yml @@ -10303,6 +10303,19 @@ tools: label-banner-text: "Văn bản trên biểu ngữ:" placeholder-enter-motd-banner-text-here: Nhập nội dung banner MOTD vào đây... title-generated-banner: Biểu ngữ được tạo + xml-diff: + title: So sánh XML + description: So sánh hai tài liệu XML và tìm ra điểm khác biệt giữa chúng. + texts: + message-invalid-xml-format: Định dạng XML không hợp lệ + label-your-first-xml: XML đầu tiên của bạn + placeholder-paste-your-first-xml-here: Dán đoạn mã XML đầu tiên của bạn vào đây... + label-your-xml-to-compare: Tệp XML của bạn để so sánh + placeholder-paste-your-xml-to-compare-here: Hãy dán mã XML của bạn vào đây để so sánh... + xml-diff-viewer: + texts: + the-provided-xmls-are-the-same: Các tệp XML được cung cấp đều giống nhau. + only-show-differences: Chỉ hiển thị sự khác biệt spanCopyable: copy: Sao chép vào bảng tạm copied: Đã sao chép! diff --git a/locales/zh-TW.yml b/locales/zh-TW.yml index 9a74cb34..6514ba61 100644 --- a/locales/zh-TW.yml +++ b/locales/zh-TW.yml @@ -9885,6 +9885,19 @@ tools: label-banner-text: 橫幅文字: placeholder-enter-motd-banner-text-here: 在此輸入每日比賽橫幅文字… title-generated-banner: 產生的橫幅 + xml-diff: + title: XML差異 + description: 比較兩個 XML 文檔,找出它們之間的差異。 + texts: + message-invalid-xml-format: 無效的 XML 格式 + label-your-first-xml: 你的第一個 XML + placeholder-paste-your-first-xml-here: 把你的第一個 XML 檔案貼到這裡… + label-your-xml-to-compare: 要比較的 XML + placeholder-paste-your-xml-to-compare-here: 請將要比較的 XML 檔案貼到這裡… + xml-diff-viewer: + texts: + the-provided-xmls-are-the-same: 提供的 XML 檔案相同 + only-show-differences: 僅顯示差異 collapsibleToolMenu: text: expanding: 正在展開…… diff --git a/locales/zh.yml b/locales/zh.yml index 0d0507e2..29bedfd3 100644 --- a/locales/zh.yml +++ b/locales/zh.yml @@ -9893,6 +9893,19 @@ tools: label-banner-text: 横幅文字: placeholder-enter-motd-banner-text-here: 在此输入每日比赛横幅文字…… title-generated-banner: 生成的横幅 + xml-diff: + title: XML差异 + description: 比较两个 XML 文档,找出它们之间的差异。 + texts: + message-invalid-xml-format: 无效的 XML 格式 + label-your-first-xml: 你的第一个 XML + placeholder-paste-your-first-xml-here: 把你的第一个 XML 文件粘贴到这里…… + label-your-xml-to-compare: 要比较的 XML + placeholder-paste-your-xml-to-compare-here: 请将要比较的 XML 文件粘贴到这里…… + xml-diff-viewer: + texts: + the-provided-xmls-are-the-same: 提供的 XML 文件相同 + only-show-differences: 仅显示差异 collapsibleToolMenu: text: expanding: 正在展开…… diff --git a/src/tools/xml-diff/diff-viewer/xml-diff-viewer.vue b/src/tools/xml-diff/diff-viewer/xml-diff-viewer.vue new file mode 100644 index 00000000..3e99aa27 --- /dev/null +++ b/src/tools/xml-diff/diff-viewer/xml-diff-viewer.vue @@ -0,0 +1,114 @@ + + + + + diff --git a/src/tools/xml-diff/index.ts b/src/tools/xml-diff/index.ts new file mode 100644 index 00000000..519138e6 --- /dev/null +++ b/src/tools/xml-diff/index.ts @@ -0,0 +1,13 @@ +import { defineTool } from '../tool'; +import { translate as t } from '@/plugins/i18n.plugin'; + +export const tool = defineTool({ + name: t('tools.xml-diff.title'), + path: '/xml-diff', + description: t('tools.xml-diff.description'), + keywords: ['xml', 'diff', 'compare', 'difference'], + component: () => import('./xml-diff.vue'), + icon: defineAsyncComponent(() => import('@vicons/material/es/CompareArrowsRound')), + createdAt: new Date('2026-11-22'), + category: 'XML', +}); diff --git a/src/tools/xml-diff/xml-diff.e2e.spec.ts b/src/tools/xml-diff/xml-diff.e2e.spec.ts new file mode 100644 index 00000000..72281840 --- /dev/null +++ b/src/tools/xml-diff/xml-diff.e2e.spec.ts @@ -0,0 +1,51 @@ +import { expect, test } from '@playwright/test'; + +test.describe('Tool - XML diff', () => { + test.beforeEach(async ({ page }) => { + await page.goto('/xml-diff'); + }); + + test('Has correct title', async ({ page }) => { + await expect(page).toHaveTitle('XML diff - IT Tools'); + }); + + test('Identical XMLs have a custom result message', async ({ page }) => { + await page.getByTestId('leftXml').fill('baz'); + await page.getByTestId('rightXml').fill('\n baz\n'); + + const result = await page.getByTestId('diff-result').innerText(); + + expect(result).toContain('The provided XMLs are the same'); + }); + + test('Different XMLs have differences listed', async ({ page }) => { + await page.getByTestId('leftXml').fill(''); + await page.getByTestId('rightXml').fill(''); + + const result = await page.getByTestId('diff-result').innerText(); + + expect(result).toContain('{\n@foo: "bar""buz",\n@baz: "qux",\n},'); + }); + + test('Different XMLs have only differences listed when "Only show differences" is checked', async ({ page }) => { + await page.getByTestId('leftXml').fill(''); + await page.getByTestId('rightXml').fill(''); + await page.getByRole('switch').click(); + + const result = await page.getByTestId('diff-result').innerText(); + + expect(result).toContain('{\n@baz: "qux",\n},'); + expect(result).not.toContain('foo'); + }); + + test('An element going from a single occurrence to several is diffed cleanly, not as a type change', async ({ + page, + }) => { + await page.getByTestId('leftXml').fill('A'); + await page.getByTestId('rightXml').fill('AB'); + + const result = await page.getByTestId('diff-result').innerText(); + + expect(result).toContain('item: [\n"A",\n"B",\n],'); + }); +}); diff --git a/src/tools/xml-diff/xml-diff.parser.test.ts b/src/tools/xml-diff/xml-diff.parser.test.ts new file mode 100644 index 00000000..e9aace19 --- /dev/null +++ b/src/tools/xml-diff/xml-diff.parser.test.ts @@ -0,0 +1,65 @@ +// @vitest-environment jsdom +import { describe, expect, it } from 'vitest'; +import { isValidXML, parseXml } from './xml-diff.parser'; + +describe('xml-diff parser', () => { + describe('parseXml', () => { + it('returns undefined for an empty string', () => { + expect(parseXml('')).toBeUndefined(); + expect(parseXml(' ')).toBeUndefined(); + }); + + it('returns undefined for invalid xml', () => { + expect(parseXml('')).toBeUndefined(); + }); + + it('parses a leaf element to its text content', () => { + expect(parseXml('bar')).toEqual('bar'); + }); + + it('parses an empty element to an empty string', () => { + expect(parseXml('')).toEqual(''); + }); + + it('parses attributes with an "@" prefix', () => { + expect(parseXml('')).toEqual({ '@a': '1', '@b': '2' }); + }); + + it('parses a single child element as a plain value', () => { + expect(parseXml('A')).toEqual({ item: 'A' }); + }); + + it('parses repeated child elements as an array', () => { + expect(parseXml('AB')).toEqual({ item: ['A', 'B'] }); + }); + + it('combines attributes, text and children', () => { + expect(parseXml('helloworld')).toEqual({ + '@id': '1', + '#text': 'hello', + child: 'world', + }); + }); + + it('ignores insignificant whitespace between tags', () => { + const withoutWhitespace = parseXml('baz'); + const withWhitespace = parseXml('\n baz\n'); + + expect(withWhitespace).toEqual(withoutWhitespace); + }); + }); + + describe('isValidXML', () => { + it('accepts an empty string', () => { + expect(isValidXML('')).toBe(true); + }); + + it('accepts valid xml', () => { + expect(isValidXML('bar')).toBe(true); + }); + + it('rejects invalid xml', () => { + expect(isValidXML('')).toBe(false); + }); + }); +}); diff --git a/src/tools/xml-diff/xml-diff.parser.ts b/src/tools/xml-diff/xml-diff.parser.ts new file mode 100644 index 00000000..5ffe5593 --- /dev/null +++ b/src/tools/xml-diff/xml-diff.parser.ts @@ -0,0 +1,74 @@ +export { isValidXML, parseXml }; + +function parseXml(rawXml: string): unknown { + const trimmed = rawXml.trim(); + + if (trimmed === '') { + return undefined; + } + + const doc = parseXmlDocument(trimmed); + + if (doc === undefined || doc.documentElement === null) { + return undefined; + } + + return elementToValue(doc.documentElement); +} + +function isValidXML(rawXml: string): boolean { + const trimmed = rawXml.trim(); + + if (trimmed === '') { + return true; + } + + return parseXmlDocument(trimmed) !== undefined; +} + +function parseXmlDocument(xml: string): Document | undefined { + const doc = new DOMParser().parseFromString(xml, 'application/xml'); + + if (doc.getElementsByTagName('parsererror').length > 0) { + return undefined; + } + + return doc; +} + +function elementToValue(element: Element): unknown { + const attributes = Array.from(element.attributes); + const childElements = Array.from(element.children); + const text = getDirectText(element); + + if (attributes.length === 0 && childElements.length === 0) { + return text; + } + + const value: Record = {}; + + for (const attribute of attributes) { + value[`@${attribute.name}`] = attribute.value; + } + + const tags = [...new Set(childElements.map((child) => child.tagName))]; + for (const tag of tags) { + const sameTagChildren = childElements.filter((child) => child.tagName === tag); + value[tag] = + sameTagChildren.length === 1 ? elementToValue(sameTagChildren[0]) : sameTagChildren.map(elementToValue); + } + + if (text !== '') { + value['#text'] = text; + } + + return value; +} + +function getDirectText(element: Element): string { + return Array.from(element.childNodes) + .filter((node) => node.nodeType === Node.TEXT_NODE || node.nodeType === Node.CDATA_SECTION_NODE) + .map((node) => node.textContent ?? '') + .join('') + .trim(); +} diff --git a/src/tools/xml-diff/xml-diff.reconcile.test.ts b/src/tools/xml-diff/xml-diff.reconcile.test.ts new file mode 100644 index 00000000..7f29e80a --- /dev/null +++ b/src/tools/xml-diff/xml-diff.reconcile.test.ts @@ -0,0 +1,63 @@ +import { describe, expect, it } from 'vitest'; +import { diff } from '../json-diff/json-diff.models'; +import { reconcileArrayShapes } from './xml-diff.reconcile'; + +describe('xml-diff reconcile', () => { + describe('reconcileArrayShapes', () => { + it('leaves matching plain values untouched', () => { + expect(reconcileArrayShapes({ item: 'A' }, { item: 'B' })).toEqual([{ item: 'A' }, { item: 'B' }]); + }); + + it('pads the shorter side when both are arrays of different lengths', () => { + expect(reconcileArrayShapes({ item: ['A'] }, { item: ['A', 'B'] })).toEqual([ + { item: ['A', undefined] }, + { item: ['A', 'B'] }, + ]); + }); + + it('wraps a single value in an array when the other side has an array for the same key', () => { + const [left, right] = reconcileArrayShapes({ item: 'A' }, { item: ['A', 'B'] }); + + expect(left).toEqual({ item: ['A', undefined] }); + expect(right).toEqual({ item: ['A', 'B'] }); + }); + + it('recurses into nested objects', () => { + const [left, right] = reconcileArrayShapes({ root: { item: 'A' } }, { root: { item: ['A', 'B'] } }); + + expect(left).toEqual({ root: { item: ['A', undefined] } }); + expect(right).toEqual({ root: { item: ['A', 'B'] } }); + }); + }); + + describe('diff after reconciliation', () => { + it('produces a clean diff when an element goes from single to repeated', () => { + const left = { item: 'A' }; + const right = { item: ['A', 'B'] }; + const [reconciledLeft, reconciledRight] = reconcileArrayShapes(left, right); + + const result = diff(reconciledLeft, reconciledRight); + + expect(result).toEqual({ + key: '', + type: 'object', + oldValue: { item: ['A', undefined] }, + value: { item: ['A', 'B'] }, + status: 'children-updated', + children: [ + { + key: 'item', + type: 'array', + oldValue: ['A', undefined], + value: ['A', 'B'], + status: 'children-updated', + children: [ + { key: 0, type: 'value', oldValue: 'A', value: 'A', status: 'unchanged' }, + { key: 1, type: 'value', oldValue: undefined, value: 'B', status: 'added' }, + ], + }, + ], + }); + }); + }); +}); diff --git a/src/tools/xml-diff/xml-diff.reconcile.ts b/src/tools/xml-diff/xml-diff.reconcile.ts new file mode 100644 index 00000000..018c7d45 --- /dev/null +++ b/src/tools/xml-diff/xml-diff.reconcile.ts @@ -0,0 +1,60 @@ +export { reconcileArrayShapes }; + +/** + * XML has no way to know, from a single document, whether a repeated element + * could also legitimately appear once. `xml-diff.parser` therefore represents + * a single occurrence as a plain value and 2+ occurrences as an array, which + * means the same element key can land on different shapes on each side of the + * diff (e.g. `item: {...}` on the left, `item: [{...}, {...}]` on the right). + * Diffing an object against an array directly produces nonsense, so before + * calling the generic diff we walk both trees together and wrap the + * non-array side in a single-element array wherever the two sides disagree. + */ +function reconcileArrayShapes(left: unknown, right: unknown): [unknown, unknown] { + if (Array.isArray(left) || Array.isArray(right)) { + return reconcileArrays( + Array.isArray(left) ? left : left === undefined ? [] : [left], + Array.isArray(right) ? right : right === undefined ? [] : [right], + ); + } + + if (isPlainObject(left) && isPlainObject(right)) { + return reconcileObjects(left, right); + } + + return [left, right]; +} + +function reconcileArrays(left: unknown[], right: unknown[]): [unknown[], unknown[]] { + const maxLength = Math.max(left.length, right.length); + const reconciledLeft: unknown[] = []; + const reconciledRight: unknown[] = []; + + for (let i = 0; i < maxLength; i++) { + const [reconciledLeftItem, reconciledRightItem] = reconcileArrayShapes(left[i], right[i]); + reconciledLeft.push(reconciledLeftItem); + reconciledRight.push(reconciledRightItem); + } + + return [reconciledLeft, reconciledRight]; +} + +function reconcileObjects( + left: Record, + right: Record, +): [Record, Record] { + const reconciledLeft: Record = { ...left }; + const reconciledRight: Record = { ...right }; + + for (const key of new Set([...Object.keys(left), ...Object.keys(right)])) { + const [reconciledLeftValue, reconciledRightValue] = reconcileArrayShapes(left[key], right[key]); + reconciledLeft[key] = reconciledLeftValue; + reconciledRight[key] = reconciledRightValue; + } + + return [reconciledLeft, reconciledRight]; +} + +function isPlainObject(value: unknown): value is Record { + return typeof value === 'object' && value !== null; +} diff --git a/src/tools/xml-diff/xml-diff.vue b/src/tools/xml-diff/xml-diff.vue new file mode 100644 index 00000000..2f4727a5 --- /dev/null +++ b/src/tools/xml-diff/xml-diff.vue @@ -0,0 +1,47 @@ + + +