Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ mxMarketplace {
appDirectory = "src/CommunityCommons"
versionPathPrefix = "_Version " // the path prefix within the module to the version folder
createMigrationFile = true
includeFiles = ["$mprDir/License.txt", "$mprDir/SiemensMendixCommunityCommons__10.1.3__READMEOSS.html"]
includeFiles = ["$mprDir/License.txt", "$mprDir/SiemensMendixCommunityCommons__10.2.0__READMEOSS.html"]
}

def userLibDir = "$mprDir/userlib"
Expand Down Expand Up @@ -58,7 +58,7 @@ dependencies {
compileOnly([group: 'com.mendix', name: 'public-api', version: "$mendixPublicApiVersion"])

implementation(
[group: 'com.google.guava', name: 'guava', version: '32.0.1-jre'],
[group: 'com.google.guava', name: 'guava', version: '33.4.7-jre'],
[group: 'com.googlecode.owasp-java-html-sanitizer', name: 'owasp-java-html-sanitizer', version: '20211018.2'],
[group: 'commons-io', name: 'commons-io', version: '2.17.0'],
[group: 'org.apache.pdfbox', name: 'pdfbox', version: '2.0.30'],
Expand Down
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
@@ -1 +1 @@
version=10.1.4-SNAPSHOT
version=10.2.0-SNAPSHOT
4 changes: 4 additions & 0 deletions marketplace/release-notes/10.2.0.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
- The StringFromFile Java action now removes BOM from strings. (Ticket #242904)
- We have upgraded the Guava dependency to 33.4.7. This also removes the dependency on the jsr305 version 3.0.2 dependency, which causes some code quality scanning tools to report issues.
- We have added a warning about possible deadlocks to the commitInSeparateDatabaseTransaction Java action.
- We added the ORM.cloneObject(IContext, IMendixObject, IMendixObject, Boolean, Boolean) method. This is an overload for the ORM.cloneObject with an extra Boolean parameter 'skipIsBoth' that can be used to skip 1-on-1 associations.
Binary file modified src/CommunityCommons/CommunityCommons.mpr
Binary file not shown.

Large diffs are not rendered by default.

9 changes: 9 additions & 0 deletions src/CommunityCommons/javasource/communitycommons/ORM.java
Original file line number Diff line number Diff line change
Expand Up @@ -265,6 +265,11 @@ private static boolean isFileDocument(IMendixObject object) {

public static Boolean cloneObject(IContext c, IMendixObject source,
IMendixObject target, Boolean withAssociations) {
return cloneObject(c, source, target, withAssociations, false);
}

public static Boolean cloneObject(IContext c, IMendixObject source,
IMendixObject target, Boolean withAssociations, Boolean skipIsBoth) {
Map<String, ? extends IMendixObjectMember<?>> members = source.getMembers(c);

for (var entry : members.entrySet()) {
Expand All @@ -279,6 +284,10 @@ public static Boolean cloneObject(IContext c, IMendixObject source,
continue;
}
if (withAssociations || ((!(m instanceof MendixObjectReference) && !(m instanceof MendixObjectReferenceSet) && !(m instanceof MendixAutoNumber)))) {
if (skipIsBoth && (
(m instanceof MendixObjectReference && ((MendixObjectReference) m).isBoth()) ||
(m instanceof MendixObjectReferenceSet && ((MendixObjectReferenceSet) m).isBoth())))
continue;
target.setValue(c, entry.getKey(), m.getValue(c));
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@
import javax.swing.text.html.parser.ParserDelegator;

import org.apache.commons.io.IOUtils;
import org.apache.commons.io.input.BOMInputStream;
import org.apache.commons.text.StringEscapeUtils;
import org.owasp.html.PolicyFactory;
import org.owasp.html.Sanitizers;
Expand Down Expand Up @@ -222,10 +223,14 @@ public static String stringFromFile(IContext context, FileDocument source, Chars
return null;
}
try (InputStream f = Core.getFileDocumentContent(context, source.getMendixObject())) {
return IOUtils.toString(f, charset);
return stringFromInputStream(f, charset);
}
}

public static String stringFromInputStream(InputStream inputStream, Charset charset) throws IOException {
return IOUtils.toString(BOMInputStream.builder().setInputStream(inputStream).get(), charset);
}

public static void stringToFile(IContext context, String value, FileDocument destination) throws IOException {
stringToFile(context, value, destination, StandardCharsets.UTF_8);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@

/**
* This function commits an object in a seperate context and transaction, making sure it gets persisted in the database (regarding which exception happens after invocation).
*
* Please note that this action is prone to deadlock. For example if you commit an object in one transaction and then use this action to commit the same object in a separate transaction. We do not recommend the use of this action.
*/
public class commitInSeparateDatabaseTransaction extends CustomJavaAction<java.lang.Boolean>
{
Expand Down
32 changes: 32 additions & 0 deletions src/test/communitycommons/StringUtilsTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,10 @@
import org.owasp.html.PolicyFactory;
import org.owasp.html.Sanitizers;

import java.io.ByteArrayInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.nio.charset.Charset;
import java.security.DigestException;
import java.security.NoSuchAlgorithmException;

Expand Down Expand Up @@ -170,4 +174,32 @@ public void testHash() throws DigestException, NoSuchAlgorithmException {
assertEquals(StringUtils.hash(originalString), StringUtils.hash(originalString, length));
assertEquals(StringUtils.hash(originalString), hashedString);
}

@Test
public void testStringFromInputStream() throws IOException {
Charset utf8 = Charset.forName("UTF-8");
Charset utf16 = Charset.forName("UTF-16");
Charset utf16be = Charset.forName("UTF-16BE");
Charset utf16le = Charset.forName("UTF-16LE");

String text = "hello";

assertEquals(text, testStringFromInputStream(text, utf8));
assertEquals(text, testStringFromInputStream(text, utf16));
assertEquals(text, testStringFromInputStream(text, utf16be));
assertEquals(text, testStringFromInputStream(text, utf16le));

// BOM should be removed (UTF-8)
byte[] UTF8BOM = { (byte) 0xEF, (byte) 0xBB, (byte) 0xBF };
String textUTF8BOM = new String(UTF8BOM) + text;
assertEquals(text, testStringFromInputStream(textUTF8BOM, utf8));
}

private String testStringFromInputStream(String text, Charset charset) throws IOException {
return StringUtils.stringFromInputStream(stringToInputStream(text, charset), charset);
}

private InputStream stringToInputStream(String str, Charset charset) {
return new ByteArrayInputStream(str.getBytes(charset));
}
}