Skip to content

Commit

Permalink
Adjust logic such that empty node (i18n) corresponds to the empty string
Browse files Browse the repository at this point in the history
and is reflected as such in the manifest.json
"i18n": ""
  • Loading branch information
tobiasso85 committed Jan 5, 2021
1 parent c90b9a4 commit b651ad1
Show file tree
Hide file tree
Showing 2 changed files with 55 additions and 9 deletions.
18 changes: 9 additions & 9 deletions lib/processors/manifestCreator.js
Original file line number Diff line number Diff line change
Expand Up @@ -347,10 +347,9 @@ async function createManifest(libraryResource, libBundle, descriptorVersion, _in

return osComponents.length > 0 ? osComponents : undefined;
}
const i18nAppData = findChild(manifestAppData, "i18n");
const i18nText = getChildTextContent(manifestAppData, "i18n");
let i18n;
if (i18nAppData) {
const i18nText = i18nAppData._; // text content
if (typeof i18nText === "string") {
i18n = createI18nSection(i18nText, i18nToSupportedLocales);
log.verbose(`sap.app/i18n taken from .library appData: '%s'`, i18nText);
}
Expand Down Expand Up @@ -487,10 +486,8 @@ async function createManifest(libraryResource, libBundle, descriptorVersion, _in
// - from .library/appData/manifest/sap.ui5/library/i18n
// - from library resources (if "messagebundle.properties" exists)
function i18n() {
const i18nElement = findChild(libraryAppData, "i18n");
let i18n = null;
if ( i18nElement ) {
i18n = i18nElement._; // text content
let i18n = getChildTextContent(libraryAppData, "i18n");
if ( typeof i18n === "string") {
if ( i18n === "false" ) {
return false;
} else if ( i18n === "true" ) {
Expand All @@ -505,6 +502,9 @@ async function createManifest(libraryResource, libBundle, descriptorVersion, _in
return false;
}
}
if (i18n === undefined) {
return false;
}
return createI18nSection(i18n, i18nToSupportedLocales);
}

Expand Down Expand Up @@ -568,8 +568,8 @@ async function createManifest(libraryResource, libBundle, descriptorVersion, _in
* <code>null</code> if given i18n String is <code>null</code>
*/
function createI18nSection(i18n, i18nToSupportedLocales) {
if (!i18n) {
return null;
if (i18n === undefined) {
return undefined;
}
if (!i18n.endsWith(".properties")) {
return i18n;
Expand Down
46 changes: 46 additions & 0 deletions test/lib/processors/manifestCreator.js
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,52 @@ test.serial("default manifest creation", async (t) => {
t.is(await result.getString(), expectedManifestContent, "Correct result returned");
});

test.serial("default manifest creation i18n empty string", async (t) => {
const {manifestCreator, errorLogStub} = t.context;
const prefix = "/resources/sap/ui/mine/";
const libraryResource = {
getPath: () => {
return prefix + ".library";
},
getString: async () => {
return `<?xml version="1.0" encoding="UTF-8" ?>
<library xmlns="http://www.sap.com/sap.ui.library.xsd" >
<name>library.e</name>
<vendor>SAP SE</vendor>
<copyright>my copyright</copyright>
<version>1.0.0</version>
<documentation>Library E</documentation>
<dependencies>
<dependency>
<libraryName>sap.ui.core</libraryName>
</dependency>
</dependencies>
<appData>
<manifest xmlns="http://www.sap.com/ui5/buildext/manifest">
<i18n></i18n>
</manifest>
</appData>
</library>`;
},
_project: {
dependencies: [{
metadata: {
name: "sap.ui.core"
}
}]
}
};

t.is(errorLogStub.callCount, 0);
const expectedManifestContentObjectModified = expectedManifestContentObject();
expectedManifestContentObjectModified["sap.app"]["i18n"] = "";
const expectedManifestContent = JSON.stringify(expectedManifestContentObjectModified, null, 2);
const result = await manifestCreator({libraryResource, resources: [], options: {}});
t.is(await result.getString(), expectedManifestContent, "Correct result returned");
});

test.serial("default manifest creation with special characters", async (t) => {
const {manifestCreator, errorLogStub} = t.context;
const prefix = "/resources/sap/ui/mine/";
Expand Down

0 comments on commit b651ad1

Please sign in to comment.