Skip to content

Feature - Hapus karakter "/" jika ada diakhir dari hostname #37

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

Merged
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: 4 additions & 0 deletions lib/core/util/helper.dart
Original file line number Diff line number Diff line change
Expand Up @@ -101,4 +101,8 @@ class Helper {
return ConstantErrorMessage().failureUnknown;
}
}

String removeTrailingSlash(String input) {
return input.replaceAll(RegExp(r'/+$'), '');
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,7 @@ class _SetupCredentialPageState extends State<SetupCredentialPage> {
) as bool?;
}
if (isContinue != null && isContinue) {
final hostname = controllerHostname.text.trim();
final hostname = helper.removeTrailingSlash(controllerHostname.text.trim()).trim();
await sharedPreferencesManager.putString(SharedPreferencesManager.keyDomainApi, hostname);
helper.setDomainApiToFlavor(hostname);
di.init();
Expand Down
2 changes: 1 addition & 1 deletion pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ dependencies:

# A cross platform plugin for displaying and scheduling local notifications for Flutter applications
# with the ability to customize for each platform.
flutter_local_notifications: ^17.1.2
flutter_local_notifications: 13.0.0

# The Font Awesome Icon pack available as Flutter Icons. Provides 1600 additional icons to use
# in your apps.
Expand Down
21 changes: 21 additions & 0 deletions test/util/helper_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -170,4 +170,25 @@ void main() {
expect(unknownFailure, constantErrorMessage.failureUnknown);
},
);

test(
'pastikan function removeTrailingSlash bisa menghapus karakter "/" diakhir dari sebuah string.',
() async {
// arrange
const input = 'https://example.com/';
const input2 = 'https://example.com';
const input3 = 'https://example.com////';
const output = 'https://example.com';

// act
final actual1 = helper.removeTrailingSlash(input);
final actual2 = helper.removeTrailingSlash(input2);
final actual3 = helper.removeTrailingSlash(input3);

// assert
expect(actual1, output);
expect(actual2, output);
expect(actual3, output);
},
);
}
Loading