Skip to content
This repository was archived by the owner on Aug 31, 2021. It is now read-only.

Commit 4a8c74c

Browse files
committed
[[ Bug 13096 ]] Resolve relative initial path before passing to file / folder dialogs
1 parent 264107f commit 4a8c74c

File tree

3 files changed

+55
-8
lines changed

3 files changed

+55
-8
lines changed

docs/notes/bugfix-13096.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
# Answer files with relative path

engine/src/answer.cpp

Lines changed: 35 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,8 @@ along with LiveCode. If not see <http://www.gnu.org/licenses/>. */
4242
#include "answer.h"
4343
#include "printer.h"
4444

45+
#include "osspec.h"
46+
4547
const char *MCdialogtypes[] =
4648
{
4749
"plain",
@@ -492,6 +494,17 @@ Exec_errors MCAnswer::exec_file(MCExecPoint& ep, const char *p_title)
492494
if (!t_error && !MCSecureModeCanAccessDisk())
493495
t_error = EE_DISK_NOPERM;
494496

497+
char *t_initial_resolved;
498+
t_initial_resolved = nil;
499+
500+
if (!t_error && t_initial != nil)
501+
{
502+
// IM-2014-08-06: [[ Bug 13096 ]] Allow file dialogs to work with relative paths by resolving to absolute
503+
t_initial_resolved = MCS_get_canonical_path(t_initial);
504+
if (nil == t_initial_resolved)
505+
t_error == EE_NO_MEMORY;
506+
}
507+
495508
if (!t_error)
496509
{
497510
if (MCsystemFS && MCscreen -> hasfeature ( PLATFORM_FEATURE_OS_FILE_DIALOGS ) )
@@ -503,23 +516,26 @@ Exec_errors MCAnswer::exec_file(MCExecPoint& ep, const char *p_title)
503516
t_options |= MCA_OPTION_PLURAL;
504517

505518
if (t_types != NULL)
506-
MCA_file_with_types(ep, p_title, t_prompt, t_type_strings, t_type_count, t_initial, t_options);
519+
MCA_file_with_types(ep, p_title, t_prompt, t_type_strings, t_type_count, t_initial_resolved, t_options);
507520
else
508-
MCA_file(ep, p_title, t_prompt, t_filter, t_initial, t_options);
521+
MCA_file(ep, p_title, t_prompt, t_filter, t_initial_resolved, t_options);
509522
}
510523
else
511524
{
512525
MCExecPoint ep2(ep);
513526
ep2 . clear();
514527
for(uint4 t_type = 0; t_type < t_type_count; ++t_type)
515528
ep2 . concatcstring(t_type_strings[t_type], EC_RETURN, t_type == 0);
516-
t_error = exec_custom(ep, MCfsnamestring, mode == AT_FILE ? "file" : "files", 5, p_title, *t_prompt, *t_filter, *t_initial, ep2 . getsvalue() . getstring());
529+
t_error = exec_custom(ep, MCfsnamestring, mode == AT_FILE ? "file" : "files", 5, p_title, *t_prompt, *t_filter, t_initial_resolved, ep2 . getsvalue() . getstring());
517530
}
518531

519532
if (ep . getsvalue() == MCnullmcstring && t_types == NULL)
520533
MCresult -> sets(MCcancelstring);
521534
}
522535

536+
if (t_initial_resolved != nil)
537+
MCCStringFree(t_initial_resolved);
538+
523539
delete[] t_types;
524540
delete t_type_strings;
525541

@@ -544,6 +560,17 @@ Exec_errors MCAnswer::exec_folder(MCExecPoint& ep, const char *p_title)
544560
if (!t_error && !MCSecureModeCanAccessDisk())
545561
t_error = EE_DISK_NOPERM;
546562

563+
char *t_initial_resolved;
564+
t_initial_resolved = nil;
565+
566+
if (!t_error && t_initial != nil)
567+
{
568+
// IM-2014-08-06: [[ Bug 13096 ]] Allow file dialogs to work with relative paths by resolving to absolute
569+
t_initial_resolved = MCS_get_canonical_path(t_initial);
570+
if (nil == t_initial_resolved)
571+
t_error == EE_NO_MEMORY;
572+
}
573+
547574
if (!t_error)
548575
{
549576
unsigned int t_options = 0;
@@ -553,14 +580,17 @@ Exec_errors MCAnswer::exec_folder(MCExecPoint& ep, const char *p_title)
553580
t_options |= MCA_OPTION_PLURAL;
554581

555582
if (MCsystemFS)
556-
MCA_folder(ep, p_title, t_prompt, t_initial, t_options);
583+
MCA_folder(ep, p_title, t_prompt, t_initial_resolved, t_options);
557584
else
558-
t_error = exec_custom(ep, MCfsnamestring, mode == AT_FOLDER ? "folder" : "folders", 4, p_title, *t_prompt, NULL, *t_initial);
585+
t_error = exec_custom(ep, MCfsnamestring, mode == AT_FOLDER ? "folder" : "folders", 4, p_title, *t_prompt, NULL, t_initial_resolved);
559586

560587
if (ep . getsvalue() == MCnullmcstring)
561588
MCresult -> sets(MCcancelstring);
562589
}
563590

591+
if (t_initial_resolved != nil)
592+
MCCStringFree(t_initial_resolved);
593+
564594
return t_error;
565595
}
566596
#endif /* MCAnswer::exec_folder */

engine/src/ask.cpp

Lines changed: 19 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,8 @@ along with LiveCode. If not see <http://www.gnu.org/licenses/>. */
3737
#include "dispatch.h"
3838
#include "securemode.h"
3939

40+
#include "osspec.h"
41+
4042
#include "globals.h"
4143

4244
#include "meta.h"
@@ -366,6 +368,17 @@ Exec_errors MCAsk::exec_file(MCExecPoint& ep, const char *p_title)
366368
if (!t_error && !MCSecureModeCanAccessDisk())
367369
t_error = EE_DISK_NOPERM;
368370

371+
char *t_initial_resolved;
372+
t_initial_resolved = nil;
373+
374+
if (!t_error && t_initial != nil)
375+
{
376+
// IM-2014-08-06: [[ Bug 13096 ]] Allow file dialogs to work with relative paths by resolving to absolute
377+
t_initial_resolved = MCS_get_canonical_path(t_initial);
378+
if (nil == t_initial_resolved)
379+
t_error == EE_NO_MEMORY;
380+
}
381+
369382
if (!t_error)
370383
{
371384
if (MCsystemFS)
@@ -375,9 +388,9 @@ Exec_errors MCAsk::exec_file(MCExecPoint& ep, const char *p_title)
375388
t_options |= MCA_OPTION_SHEET;
376389

377390
if (t_types != NULL)
378-
MCA_ask_file_with_types(ep, p_title, t_prompt, t_type_strings, t_type_count, t_initial, t_options);
391+
MCA_ask_file_with_types(ep, p_title, t_prompt, t_type_strings, t_type_count, t_initial_resolved, t_options);
379392
else
380-
MCA_ask_file(ep, p_title, t_prompt, t_filter, t_initial, t_options);
393+
MCA_ask_file(ep, p_title, t_prompt, t_filter, t_initial_resolved, t_options);
381394
}
382395
else
383396
{
@@ -386,13 +399,16 @@ Exec_errors MCAsk::exec_file(MCExecPoint& ep, const char *p_title)
386399
ep2 . clear();
387400
for(uint4 t_type = 0; t_type < t_type_count; ++t_type)
388401
ep2 . concatcstring(t_type_strings[t_type], EC_RETURN, t_type == 0);
389-
t_error = exec_custom(ep, t_cancelled, MCfsnamestring, mode == AT_FILE ? "file" : "files", 5, p_title, *t_prompt, *t_filter, *t_initial, ep2 . getsvalue() . getstring());
402+
t_error = exec_custom(ep, t_cancelled, MCfsnamestring, mode == AT_FILE ? "file" : "files", 5, p_title, *t_prompt, *t_filter, t_initial_resolved, ep2 . getsvalue() . getstring());
390403
}
391404

392405
if (ep . getsvalue() == MCnullmcstring && t_types == NULL)
393406
MCresult -> sets(MCcancelstring);
394407
}
395408

409+
if (t_initial_resolved != nil)
410+
MCCStringFree(t_initial_resolved);
411+
396412
delete[] t_types;
397413
delete t_type_strings;
398414

0 commit comments

Comments
 (0)