001/*
002 * Copyright 2015-2020 the original author or authors
003 *
004 * This software is licensed under the Apache License, Version 2.0,
005 * the GNU Lesser General Public License version 2 or later ("LGPL")
006 * and the WTFPL.
007 * You may choose either license to govern your use of this software only
008 * upon the condition that you accept all of the terms of either
009 * the Apache License 2.0, the LGPL 2.1+ or the WTFPL.
010 */
011package org.minidns.idna;
012
013import java.net.IDN;
014
015import org.minidns.dnsname.DnsName;
016
017public class DefaultIdnaTransformator implements IdnaTransformator {
018
019    @Override
020    public String toASCII(String input) {
021        // Special case if input is ".", i.e. a string containing only a single dot character. This is a workaround for
022        // IDN.toASCII() implementations throwing an IllegalArgumentException on this input string (for example Android
023        // APIs level 26, see https://issuetracker.google.com/issues/113070416).
024        if (DnsName.ROOT.ace.equals(input)) {
025            return DnsName.ROOT.ace;
026        }
027
028        return IDN.toASCII(input);
029    }
030
031    @Override
032    public String toUnicode(String input) {
033        return IDN.toUnicode(input);
034    }
035
036}