@@ -1288,17 +1288,27 @@ bool Tag::renameNoteFileNamesOfLinks(const QString &oldFileName, const QString &
12881288
12891289/* *
12901290 * Renames the note sub folder paths of note links
1291+ *
1292+ * Uses prefix-only substitution to avoid accidentally modifying sibling paths
1293+ * that share the same prefix (e.g. renaming "work" must not affect "workplace"),
1294+ * and to prevent the global replace() from corrupting paths that contain the
1295+ * old folder name in a deeper component (e.g. "A/A/note" when renaming "A").
12911296 */
12921297bool Tag::renameNoteSubFolderPathsOfLinks (const QString &oldPath, const QString &newPath) {
12931298 QSqlDatabase db = DatabaseService::getNoteFolderDatabase ();
12941299 QSqlQuery query (db);
1300+ // Replace only the prefix: match the exact path or direct/deep children
1301+ // (separated by "/"), then concatenate newPath with the remainder of the
1302+ // original string so that inner occurrences of the old name are untouched.
12951303 query.prepare (
12961304 QStringLiteral (" UPDATE noteTagLink SET note_sub_folder_path = "
1297- " replace(note_sub_folder_path, :oldPath, :newPath) WHERE "
1298- " note_sub_folder_path LIKE :oldPathLike" ));
1305+ " :newPath || substr(note_sub_folder_path, length(:oldPath2) + 1) "
1306+ " WHERE note_sub_folder_path = :oldPath "
1307+ " OR note_sub_folder_path LIKE :oldPathChildLike" ));
12991308
13001309 query.bindValue (QStringLiteral (" :oldPath" ), oldPath);
1301- query.bindValue (QStringLiteral (" :oldPathLike" ), oldPath + " %" );
1310+ query.bindValue (QStringLiteral (" :oldPath2" ), oldPath);
1311+ query.bindValue (QStringLiteral (" :oldPathChildLike" ), oldPath + " /%" );
13021312 query.bindValue (QStringLiteral (" :newPath" ), newPath);
13031313
13041314 if (!query.exec ()) {
0 commit comments