Skip to content

Commit

Permalink
Merge pull request #592 from poppingmoon/punycode
Browse files Browse the repository at this point in the history
ログイン時にUnicode表記されたホストをpunycodeに変換する
  • Loading branch information
shiosyakeyakini-info authored Jul 14, 2024
2 parents d302848 + 363c489 commit 92a28e8
Show file tree
Hide file tree
Showing 5 changed files with 29 additions and 3 deletions.
15 changes: 15 additions & 0 deletions lib/util/punycode.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import 'package:punycode/punycode.dart';

String toAscii(String host) {
return host.splitMapJoin(
'.',
onNonMatch: (n) {
if (RegExp(r'[^\x00-\x7F]').hasMatch(n)) {
try {
return 'xn--${punycodeEncode(n)}';
} catch (_) {}
}
return n;
},
);
}
3 changes: 2 additions & 1 deletion lib/view/login_page/api_key_login.dart
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import 'package:auto_route/auto_route.dart';
import 'package:flutter/material.dart';
import 'package:miria/providers.dart';
import 'package:miria/router/app_router.dart';
import 'package:miria/util/punycode.dart';
import 'package:miria/view/common/error_dialog_handler.dart';
import 'package:miria/view/common/modal_indicator.dart';
import 'package:miria/view/login_page/centraing_widget.dart';
Expand Down Expand Up @@ -32,7 +33,7 @@ class APiKeyLoginState extends ConsumerState<ApiKeyLogin> {
IndicatorView.showIndicator(context);
await ref
.read(accountRepositoryProvider.notifier)
.loginAsToken(serverController.text, apiKeyController.text);
.loginAsToken(toAscii(serverController.text), apiKeyController.text);

if (!mounted) return;
context.pushRoute(TimeLineRoute(
Expand Down
5 changes: 3 additions & 2 deletions lib/view/login_page/mi_auth_login.dart
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import 'package:auto_route/auto_route.dart';
import 'package:flutter/material.dart';
import 'package:miria/providers.dart';
import 'package:miria/router/app_router.dart';
import 'package:miria/util/punycode.dart';
import 'package:miria/view/common/error_dialog_handler.dart';
import 'package:miria/view/common/modal_indicator.dart';
import 'package:miria/view/login_page/centraing_widget.dart';
Expand Down Expand Up @@ -31,7 +32,7 @@ class MiAuthLoginState extends ConsumerState<MiAuthLogin> {
IndicatorView.showIndicator(context);
await ref
.read(accountRepositoryProvider.notifier)
.validateMiAuth(serverController.text);
.validateMiAuth(toAscii(serverController.text));
if (!mounted) return;
context.pushRoute(
TimeLineRoute(
Expand Down Expand Up @@ -88,7 +89,7 @@ class MiAuthLoginState extends ConsumerState<MiAuthLogin> {
onPressed: () {
ref
.read(accountRepositoryProvider.notifier)
.openMiAuth(serverController.text)
.openMiAuth(toAscii(serverController.text))
.expectFailure(context);
setState(() {
isAuthed = true;
Expand Down
8 changes: 8 additions & 0 deletions pubspec.lock
Original file line number Diff line number Diff line change
Expand Up @@ -1161,6 +1161,14 @@ packages:
url: "https://pub.dev"
source: hosted
version: "1.2.3"
punycode:
dependency: "direct main"
description:
name: punycode
sha256: "39b874cc1f78b94e57db17e74b3f2ba2a96e25c0bebdcc8a571614dccda0ff0c"
url: "https://pub.dev"
source: hosted
version: "1.0.0"
receive_sharing_intent:
dependency: "direct main"
description:
Expand Down
1 change: 1 addition & 0 deletions pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@ dependencies:
volume_controller: ^2.0.7
window_manager: ^0.3.8
shared_preference_app_group: ^1.0.0+1
punycode: ^1.0.0

dependency_overrides:
image_editor:
Expand Down

0 comments on commit 92a28e8

Please sign in to comment.