diff --git a/app/src/main/java/org/zotero/android/database/requests/StoreItemsDbResponseRequest.kt b/app/src/main/java/org/zotero/android/database/requests/StoreItemsDbResponseRequest.kt index fad8afc..b0faf1e 100644 --- a/app/src/main/java/org/zotero/android/database/requests/StoreItemsDbResponseRequest.kt +++ b/app/src/main/java/org/zotero/android/database/requests/StoreItemsDbResponseRequest.kt @@ -301,9 +301,19 @@ class StoreItemDbRequest( field.key == FieldKeys.Item.title || field.baseKey == FieldKeys.Item.title -> { item.baseTitle = value } + field.key == FieldKeys.Item.note && item.rawType == ItemTypes.note -> { - item.baseTitle = NotePreviewGenerator.preview(value) ?: "" - item.htmlFreeContent = if(value.isEmpty()) null else value + try { + item.baseTitle = NotePreviewGenerator.preview(value) ?: "" + } catch (e: Exception) { + Timber.e( + e, + "StoreItemsDbResponseRequest: unable to set baseTitle after value was processed by NotePreviewGenerator. Original value = ${ + value.take(210) + }" + ) + } + item.htmlFreeContent = value.ifEmpty { null } } field.key == FieldKeys.Item.Annotation.comment && item.rawType == ItemTypes.annotation -> { item.htmlFreeContent = if(value.isEmpty()) null else value.strippedRichTextTags diff --git a/app/src/main/java/org/zotero/android/sync/NotePreviewGenerator.kt b/app/src/main/java/org/zotero/android/sync/NotePreviewGenerator.kt index 87927e2..f159704 100644 --- a/app/src/main/java/org/zotero/android/sync/NotePreviewGenerator.kt +++ b/app/src/main/java/org/zotero/android/sync/NotePreviewGenerator.kt @@ -11,7 +11,7 @@ class NotePreviewGenerator { return null } var stripped = note.strippedHtmlTags.basicUnescape - stripped = stripped.replace("\t", "") + stripped = stripped.replace("\t", "") stripped = stripped.split("\\r\\n|\\n|\\r").firstOrNull() ?: stripped stripped = stripped.trim() @@ -19,6 +19,18 @@ class NotePreviewGenerator { if (stripped.length > maxCharacters) { stripped = stripped.take(maxCharacters) } + if (stripped.isNotEmpty()) { + //Has a valid surrogate pair at the very end of the stripped text + if (stripped.hasSurrogatePairAt(stripped.length - 2)) { + return stripped + } + + val lastChar = stripped[stripped.length - 1] + //If last char is the surrogate without a pair + if (lastChar.isLowSurrogate() || lastChar.isHighSurrogate()) { + return stripped.substring(0, stripped.length - 1) + } + } return stripped } } diff --git a/buildSrc/src/main/kotlin/BuildConfig.kt b/buildSrc/src/main/kotlin/BuildConfig.kt index de0d1b7..bb47f8a 100644 --- a/buildSrc/src/main/kotlin/BuildConfig.kt +++ b/buildSrc/src/main/kotlin/BuildConfig.kt @@ -4,7 +4,7 @@ object BuildConfig { const val compileSdkVersion = 34 const val targetSdk = 34 - val versionCode = 107 // Must be updated on every build + val versionCode = 108 // Must be updated on every build val version = Version( major = 1, minor = 0,