Skip to content

Commit 23128ff

Browse files
authored
Merge pull request #37 from CoderJava/feature/hapus-karakter-slash-jika-ada-diakhir-dari-hostname
Feature - Hapus karakter "/" jika ada diakhir dari hostname
2 parents af794fb + 7e10f16 commit 23128ff

File tree

4 files changed

+27
-2
lines changed

4 files changed

+27
-2
lines changed

lib/core/util/helper.dart

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -101,4 +101,8 @@ class Helper {
101101
return ConstantErrorMessage().failureUnknown;
102102
}
103103
}
104+
105+
String removeTrailingSlash(String input) {
106+
return input.replaceAll(RegExp(r'/+$'), '');
107+
}
104108
}

lib/feature/presentation/page/setup_credential/setup_credential_page.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -148,7 +148,7 @@ class _SetupCredentialPageState extends State<SetupCredentialPage> {
148148
) as bool?;
149149
}
150150
if (isContinue != null && isContinue) {
151-
final hostname = controllerHostname.text.trim();
151+
final hostname = helper.removeTrailingSlash(controllerHostname.text.trim()).trim();
152152
await sharedPreferencesManager.putString(SharedPreferencesManager.keyDomainApi, hostname);
153153
helper.setDomainApiToFlavor(hostname);
154154
di.init();

pubspec.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,7 @@ dependencies:
9999

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

104104
# The Font Awesome Icon pack available as Flutter Icons. Provides 1600 additional icons to use
105105
# in your apps.

test/util/helper_test.dart

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -170,4 +170,25 @@ void main() {
170170
expect(unknownFailure, constantErrorMessage.failureUnknown);
171171
},
172172
);
173+
174+
test(
175+
'pastikan function removeTrailingSlash bisa menghapus karakter "/" diakhir dari sebuah string.',
176+
() async {
177+
// arrange
178+
const input = 'https://example.com/';
179+
const input2 = 'https://example.com';
180+
const input3 = 'https://example.com////';
181+
const output = 'https://example.com';
182+
183+
// act
184+
final actual1 = helper.removeTrailingSlash(input);
185+
final actual2 = helper.removeTrailingSlash(input2);
186+
final actual3 = helper.removeTrailingSlash(input3);
187+
188+
// assert
189+
expect(actual1, output);
190+
expect(actual2, output);
191+
expect(actual3, output);
192+
},
193+
);
173194
}

0 commit comments

Comments
 (0)