On Thu, Nov 13, 2008 at 2:39 AM, Matthew Toseland <toad at amphibian.dyndns.org> wrote: > On Tuesday 11 November 2008 19:19, xor at freenetproject.org wrote: >> Author: xor >> Date: 2008-11-11 19:19:37 +0000 (Tue, 11 Nov 2008) >> New Revision: 23489 >> >> Modified: >> trunk/plugins/Freetalk/FTBoard.java >> Log: >> Implement the following restriction on board names: >> If the name contains any letters different than A to Z and '.' then the part > of the name before the first dot has to be only letters of A to Z specifying > an ISO language code. This allows users which cannot type the letters of that > language to filter based on the first part because they then can type its > name. Further, it is polite to specify what language a board is in if it is > not English, therefore require the ISO code.
Good luck with iso langauage code. We have lots of iso codes ISO 639-2, ISO 639-3, ISO 639-5, etc. To make things more messy -- some of them define *spoken* language, while the others define a *written* language. You are using ISO639-2 code here. Some incompatible languages under the same 639-2 code and lots of language don't even have a iso639-2. >> Modified: trunk/plugins/Freetalk/FTBoard.java >> =================================================================== >> --- trunk/plugins/Freetalk/FTBoard.java 2008-11-11 19:10:40 UTC (rev >> 23488) >> +++ trunk/plugins/Freetalk/FTBoard.java 2008-11-11 19:19:37 UTC (rev >> 23489) >> @@ -3,8 +3,13 @@ >> * http://www.gnu.org/ for further details of the GPL. */ >> package plugins.Freetalk; >> >> +import java.util.Arrays; >> +import java.util.HashSet; >> import java.util.Iterator; >> +import java.util.Locale; >> >> +import plugins.Freetalk.exceptions.InvalidParameterException; >> + >> import com.db4o.ObjectContainer; >> import com.db4o.ObjectSet; >> import com.db4o.query.Query; >> @@ -25,6 +30,8 @@ >> private transient final FTMessageManager mMessageManager; >> >> private final String mName; >> + >> + private static transient final HashSet<String> ISOLanguages = new > HashSet<String>(Arrays.asList(Locale.getISOLanguages())); >> >> /** >> * Get a list of fields which the database should create an index on. >> @@ -33,9 +40,11 @@ >> return new String[] {"mName"}; >> } >> >> - public FTBoard(ObjectContainer myDB, FTMessageManager >> newMessageManager, > String newName) { >> + public FTBoard(ObjectContainer myDB, FTMessageManager >> newMessageManager, > String newName) throws InvalidParameterException { >> if(newName==null || newName.length() == 0) >> throw new IllegalArgumentException("Empty board >> name."); >> + if(!isNameValid(newName)) >> + throw new InvalidParameterException("Board names have >> to be either in > English or have an ISO language code at the beginning followed by a dot."); >> >> assert(myDB != null); >> assert(newMessageManager != null); >> @@ -48,11 +57,44 @@ >> db.store(this); >> db.commit(); >> } >> + >> + /** >> + * I suggest that we allow letters of any language in the name of a >> board > with one restriction: >> + * If the name contains any letters different than A to Z and '.' then >> the > part of the name before the first dot >> + * has to be only letters of A to Z specifying an ISO language code. >> This > allows users which cannot type the >> + * letters of that language to filter based on the first part because >> they > then can type its name. >> + * Further, it is polite to specify what language a board is in if it >> is > not English. >> + */ >> + public static boolean isNameValid(String name) { >> + int firstDot = name.indexOf('.'); >> + String firstPart = firstDot!=-1 ? name.substring(0, firstDot) >> : name; >> >> + return name.matches("[a-zA-Z0-9.]") || >> ISOLanguages.contains(firstPart); > > So you're allowing for unofficial languages by matching *either* an ISO > language *or* an alphanumeric string? > > The rest of the name should match a whitelist of allowed punctuation > (excluding for example &<>%#), or letters (not necessarily english letters) > according to Character.isLetter(). > >> + } >> + >> + /* >> + * FIXME: >> + * We should post a warning on the interface if a user wants to post >> to a > board with a non-NNTP-valid name and show him what the NNTP client >> + * will display the board name as, as soon as we have a getNameNNTP() > function which converts the name to something displayable by NNTP >> + * readers. >> + */ >> /** >> + * Check whether the boardname is valid in the context of NNTP. >> + */ >> + public static boolean isNameValidNNTP(String name) { >> + /* >> + * FIXME: >> + * - Check the specification of NNTP and see if it allows >> anything else > than the following regular expression. >> + */ >> + >> + return name.matches("[a-zA-Z0-9.]"); >> + } >> + >> + /** >> * @return The name. >> */ >> public String getName() { >> + /* FIXME: Provide a getNameNNTP() which converts non-English >> characters > to something English and still readable maybe. */ >> return mName; >> } >> >> >> _______________________________________________ >> cvs mailing list >> cvs at freenetproject.org >> http://emu.freenetproject.org/cgi-bin/mailman/listinfo/cvs >> >> > > _______________________________________________ > Devl mailing list > Devl at freenetproject.org > http://emu.freenetproject.org/cgi-bin/mailman/listinfo/devl >
