Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix file names with & #4292

Closed
wants to merge 4 commits into from
Closed
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
12 changes: 9 additions & 3 deletions Sources/Backup/OABackupHelper.mm
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,8 @@
static NSString *ACCOUNT_DELETE_URL = [SERVER_URL stringByAppendingString:@"/userdata/delete-account"];
static NSString *SEND_CODE_URL = [SERVER_URL stringByAppendingString:@"/userdata/send-code"];
static NSString *CHECK_CODE_URL = [SERVER_URL stringByAppendingString:@"/userdata/auth/confirm-code"];
static NSCharacterSet* URL_PATH_CHARACTER_SET;


@interface OABackupHelper () <OAOnPrepareBackupListener, NSURLSessionDelegate>

Expand Down Expand Up @@ -118,7 +120,7 @@ + (OASettingsItem *) getRestoreItem:(NSArray<OASettingsItem *> *)items remoteFil
{
for (OASettingsItem *item in items)
{
if ([self.class applyItem:item type:remoteFile.type name:remoteFile.name])
if ([BackupUtils applyItem:item type:remoteFile.type name:remoteFile.name])
return item;
}
return nil;
Expand All @@ -137,6 +139,9 @@ + (OABackupHelper *)sharedInstance
- (instancetype)init
{
self = [super init];
NSMutableCharacterSet *mutableSet = [NSCharacterSet.URLQueryAllowedCharacterSet mutableCopy];
[mutableSet removeCharactersInString:@";/?:@&=+$, "];
URL_PATH_CHARACTER_SET = [mutableSet copy];
if (self)
{
_app = [OsmAndApp instance];
Expand Down Expand Up @@ -228,7 +233,7 @@ - (void) logout
{
NSMutableArray<NSString *> *filesToUpload = [NSMutableArray array];
OABackupInfo *info = self.backup.backupInfo;
if (![self.class isLimitedFilesCollectionItem:item]
if (![BackupUtils isLimitedFilesCollectionItem:item]
&& info != nil && (info.filesToUpload.count > 0 || info.filesToMerge.count > 0 || info.filesToDownload.count > 0))
{
for (OALocalFile *localFile in info.filesToUpload)
Expand Down Expand Up @@ -498,7 +503,8 @@ - (NSString *)downloadFile:(NSString *)filePath
NSMutableString *builder = [NSMutableString stringWithString:DOWNLOAD_FILE_URL];
__block BOOL firstParam = YES;
[params enumerateKeysAndObjectsUsingBlock:^(NSString * _Nonnull key, NSString * _Nonnull obj, BOOL * _Nonnull stop) {
[builder appendString:[NSString stringWithFormat:@"%@%@=%@", firstParam ? @"?" : @"&", key, [obj stringByAddingPercentEncodingWithAllowedCharacters:NSCharacterSet.URLQueryAllowedCharacterSet]]];
NSString* encodedValue = [obj stringByAddingPercentEncodingWithAllowedCharacters:URL_PATH_CHARACTER_SET];
[builder appendString:[NSString stringWithFormat:@"%@%@=%@", firstParam ? @"?" : @"&", key, encodedValue]];
firstParam = NO;
}];

Expand Down
2 changes: 2 additions & 0 deletions Sources/Backup/OACollectLocalFilesTask.m
Original file line number Diff line number Diff line change
Expand Up @@ -172,6 +172,8 @@ - (void) createLocalFile:(NSMutableArray<OALocalFile *> *)result item:(OASetting
if (_infos != nil)
{
OAUploadedFileInfo *fileInfo = _infos[[NSString stringWithFormat:@"%@___%@", [OASettingsItemType typeName:item.type], fileName]];
if (!fileInfo)
fileInfo = _infos[[NSString stringWithFormat:@"%@___%@", [OASettingsItemType typeName:item.type], fileName.precomposedStringWithCanonicalMapping]];
if (fileInfo)
{
localFile.uploadTime = fileInfo.uploadTime;
Expand Down
15 changes: 12 additions & 3 deletions Sources/Backup/OAGenerateBackupInfoTask.m
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ @implementation OAGenerateBackupInfoTask
{
NSDictionary<NSString *, OALocalFile *> *_localFiles;
NSDictionary<NSString *, OARemoteFile *> *_uniqueRemoteFiles;
NSDictionary<NSString *, OARemoteFile *> *_uniqueRemoteFilesWithDecomposedNames;
NSDictionary<NSString *, OARemoteFile *> *_deletedRemoteFiles;
void (^_onComplete)(OABackupInfo *backupInfo, NSString *error);

Expand All @@ -36,6 +37,13 @@ - (instancetype) initWithLocalFiles:(NSDictionary<NSString *, OALocalFile *> *)l
{
_localFiles = localFiles;
_uniqueRemoteFiles = uniqueRemoteFiles;
NSMutableDictionary<NSString *, OARemoteFile *>* localMap = [NSMutableDictionary dictionaryWithCapacity:_uniqueRemoteFiles.count];
for (NSString *originalKey in _uniqueRemoteFiles)
{
NSString *decomposedKey = [originalKey decomposedStringWithCanonicalMapping];
localMap[decomposedKey] = _uniqueRemoteFiles[originalKey];
}
_uniqueRemoteFilesWithDecomposedNames = localMap;
_deletedRemoteFiles = deletedRemoteFiles;
_onComplete = onComplete;
_operationLog = [[OAOperationLog alloc] initWithOperationName:@"generateBackupInfo" debug:BACKUP_DEBUG_LOGS logThreshold:0.2];
Expand Down Expand Up @@ -79,7 +87,8 @@ - (OABackupInfo *) doInBackground
OAExportSettingsType *exportType = [OAExportSettingsType findByRemoteFile:remoteFile];
if (exportType == nil || ![OAExportSettingsType isTypeEnabled:exportType] || remoteFile.isRecordedVoiceFile)
continue;
OALocalFile *localFile = _localFiles[remoteFile.getTypeNamePath];
NSString* decomposedRemoteName = remoteFile.getTypeNamePath.decomposedStringWithCanonicalMapping;
OALocalFile *localFile = _localFiles[decomposedRemoteName];
if (localFile != nil)
{
BOOL fileChangedLocally = localFile.localModifiedTime > localFile.uploadTime;
Expand Down Expand Up @@ -116,15 +125,15 @@ - (OABackupInfo *) doInBackground
}
}
}

for (OALocalFile *localFile in _localFiles.allValues)
{
OAExportSettingsType *exportType = localFile.item != nil
? [OAExportSettingsType findBySettingsItem:localFile.item]
: nil;
if (exportType == nil || ![OAExportSettingsType isTypeEnabled:exportType])
continue;

BOOL hasRemoteFile = _uniqueRemoteFiles[localFile.getTypeFileName] != nil;
BOOL hasRemoteFile = _uniqueRemoteFilesWithDecomposedNames[localFile.getTypeFileName] != nil;
BOOL fileToDelete = [info.localFilesToDelete containsObject:localFile];
if (!hasRemoteFile && !fileToDelete)
{
Expand Down