Tweaking nickname format regexes: added one that explicitly allows numbers, to be used in router setup.
This commit is contained in:
parent
f947fe5d0c
commit
d55f606cf8
@ -20,7 +20,25 @@
|
|||||||
class Nickname
|
class Nickname
|
||||||
{
|
{
|
||||||
/**
|
/**
|
||||||
* Regex fragment for pulling an arbitrarily-formated nickname.
|
* Regex fragment for pulling a formated nickname *OR* ID number.
|
||||||
|
* Suitable for router def of 'id' parameters on API actions.
|
||||||
|
*
|
||||||
|
* Not guaranteed to be valid after normalization; run the string through
|
||||||
|
* Nickname::normalize() to get the canonical form, or Nickname::isValid()
|
||||||
|
* if you just need to check if it's properly formatted.
|
||||||
|
*
|
||||||
|
* This, DISPLAY_FMT, and CANONICAL_FMT replace the old NICKNAME_FMT,
|
||||||
|
* but be aware that these should not be enclosed in []s.
|
||||||
|
*
|
||||||
|
* @fixme would prefer to define in reference to the other constants
|
||||||
|
*/
|
||||||
|
const INPUT_FMT = '(?:[0-9]+|[0-9a-zA-Z_]{1,64})';
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Regex fragment for acceptable user-formatted variant of a nickname.
|
||||||
|
* This includes some chars such as underscore which will be removed
|
||||||
|
* from the normalized canonical form, but still must fit within
|
||||||
|
* field length limits.
|
||||||
*
|
*
|
||||||
* Not guaranteed to be valid after normalization; run the string through
|
* Not guaranteed to be valid after normalization; run the string through
|
||||||
* Nickname::normalize() to get the canonical form, or Nickname::isValid()
|
* Nickname::normalize() to get the canonical form, or Nickname::isValid()
|
||||||
@ -29,7 +47,7 @@ class Nickname
|
|||||||
* This and CANONICAL_FMT replace the old NICKNAME_FMT, but be aware
|
* This and CANONICAL_FMT replace the old NICKNAME_FMT, but be aware
|
||||||
* that these should not be enclosed in []s.
|
* that these should not be enclosed in []s.
|
||||||
*/
|
*/
|
||||||
const DISPLAY_FMT = '[0-9a-zA-Z_]+';
|
const DISPLAY_FMT = '[0-9a-zA-Z_]{1,64}';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Regex fragment for checking a canonical nickname.
|
* Regex fragment for checking a canonical nickname.
|
||||||
|
@ -403,7 +403,7 @@ class Router
|
|||||||
|
|
||||||
$m->connect('api/statuses/friends_timeline/:id.:format',
|
$m->connect('api/statuses/friends_timeline/:id.:format',
|
||||||
array('action' => 'ApiTimelineFriends',
|
array('action' => 'ApiTimelineFriends',
|
||||||
'id' => Nickname::DISPLAY_FMT,
|
'id' => Nickname::INPUT_FMT,
|
||||||
'format' => '(xml|json|rss|atom)'));
|
'format' => '(xml|json|rss|atom)'));
|
||||||
|
|
||||||
$m->connect('api/statuses/home_timeline.:format',
|
$m->connect('api/statuses/home_timeline.:format',
|
||||||
@ -412,7 +412,7 @@ class Router
|
|||||||
|
|
||||||
$m->connect('api/statuses/home_timeline/:id.:format',
|
$m->connect('api/statuses/home_timeline/:id.:format',
|
||||||
array('action' => 'ApiTimelineHome',
|
array('action' => 'ApiTimelineHome',
|
||||||
'id' => Nickname::DISPLAY_FMT,
|
'id' => Nickname::INPUT_FMT,
|
||||||
'format' => '(xml|json|rss|atom)'));
|
'format' => '(xml|json|rss|atom)'));
|
||||||
|
|
||||||
$m->connect('api/statuses/user_timeline.:format',
|
$m->connect('api/statuses/user_timeline.:format',
|
||||||
@ -421,7 +421,7 @@ class Router
|
|||||||
|
|
||||||
$m->connect('api/statuses/user_timeline/:id.:format',
|
$m->connect('api/statuses/user_timeline/:id.:format',
|
||||||
array('action' => 'ApiTimelineUser',
|
array('action' => 'ApiTimelineUser',
|
||||||
'id' => Nickname::DISPLAY_FMT,
|
'id' => Nickname::INPUT_FMT,
|
||||||
'format' => '(xml|json|rss|atom)'));
|
'format' => '(xml|json|rss|atom)'));
|
||||||
|
|
||||||
$m->connect('api/statuses/mentions.:format',
|
$m->connect('api/statuses/mentions.:format',
|
||||||
@ -430,7 +430,7 @@ class Router
|
|||||||
|
|
||||||
$m->connect('api/statuses/mentions/:id.:format',
|
$m->connect('api/statuses/mentions/:id.:format',
|
||||||
array('action' => 'ApiTimelineMentions',
|
array('action' => 'ApiTimelineMentions',
|
||||||
'id' => Nickname::DISPLAY_FMT,
|
'id' => Nickname::INPUT_FMT,
|
||||||
'format' => '(xml|json|rss|atom)'));
|
'format' => '(xml|json|rss|atom)'));
|
||||||
|
|
||||||
$m->connect('api/statuses/replies.:format',
|
$m->connect('api/statuses/replies.:format',
|
||||||
@ -439,7 +439,7 @@ class Router
|
|||||||
|
|
||||||
$m->connect('api/statuses/replies/:id.:format',
|
$m->connect('api/statuses/replies/:id.:format',
|
||||||
array('action' => 'ApiTimelineMentions',
|
array('action' => 'ApiTimelineMentions',
|
||||||
'id' => Nickname::DISPLAY_FMT,
|
'id' => Nickname::INPUT_FMT,
|
||||||
'format' => '(xml|json|rss|atom)'));
|
'format' => '(xml|json|rss|atom)'));
|
||||||
|
|
||||||
$m->connect('api/statuses/retweeted_by_me.:format',
|
$m->connect('api/statuses/retweeted_by_me.:format',
|
||||||
@ -460,7 +460,7 @@ class Router
|
|||||||
|
|
||||||
$m->connect('api/statuses/friends/:id.:format',
|
$m->connect('api/statuses/friends/:id.:format',
|
||||||
array('action' => 'ApiUserFriends',
|
array('action' => 'ApiUserFriends',
|
||||||
'id' => Nickname::DISPLAY_FMT,
|
'id' => Nickname::INPUT_FMT,
|
||||||
'format' => '(xml|json)'));
|
'format' => '(xml|json)'));
|
||||||
|
|
||||||
$m->connect('api/statuses/followers.:format',
|
$m->connect('api/statuses/followers.:format',
|
||||||
@ -469,7 +469,7 @@ class Router
|
|||||||
|
|
||||||
$m->connect('api/statuses/followers/:id.:format',
|
$m->connect('api/statuses/followers/:id.:format',
|
||||||
array('action' => 'ApiUserFollowers',
|
array('action' => 'ApiUserFollowers',
|
||||||
'id' => Nickname::DISPLAY_FMT,
|
'id' => Nickname::INPUT_FMT,
|
||||||
'format' => '(xml|json)'));
|
'format' => '(xml|json)'));
|
||||||
|
|
||||||
$m->connect('api/statuses/show.:format',
|
$m->connect('api/statuses/show.:format',
|
||||||
@ -512,7 +512,7 @@ class Router
|
|||||||
|
|
||||||
$m->connect('api/users/show/:id.:format',
|
$m->connect('api/users/show/:id.:format',
|
||||||
array('action' => 'ApiUserShow',
|
array('action' => 'ApiUserShow',
|
||||||
'id' => Nickname::DISPLAY_FMT,
|
'id' => Nickname::INPUT_FMT,
|
||||||
'format' => '(xml|json)'));
|
'format' => '(xml|json)'));
|
||||||
|
|
||||||
// direct messages
|
// direct messages
|
||||||
@ -550,12 +550,12 @@ class Router
|
|||||||
|
|
||||||
$m->connect('api/friendships/create/:id.:format',
|
$m->connect('api/friendships/create/:id.:format',
|
||||||
array('action' => 'ApiFriendshipsCreate',
|
array('action' => 'ApiFriendshipsCreate',
|
||||||
'id' => Nickname::DISPLAY_FMT,
|
'id' => Nickname::INPUT_FMT,
|
||||||
'format' => '(xml|json)'));
|
'format' => '(xml|json)'));
|
||||||
|
|
||||||
$m->connect('api/friendships/destroy/:id.:format',
|
$m->connect('api/friendships/destroy/:id.:format',
|
||||||
array('action' => 'ApiFriendshipsDestroy',
|
array('action' => 'ApiFriendshipsDestroy',
|
||||||
'id' => Nickname::DISPLAY_FMT,
|
'id' => Nickname::INPUT_FMT,
|
||||||
'format' => '(xml|json)'));
|
'format' => '(xml|json)'));
|
||||||
|
|
||||||
// Social graph
|
// Social graph
|
||||||
@ -612,17 +612,17 @@ class Router
|
|||||||
|
|
||||||
$m->connect('api/favorites/:id.:format',
|
$m->connect('api/favorites/:id.:format',
|
||||||
array('action' => 'ApiTimelineFavorites',
|
array('action' => 'ApiTimelineFavorites',
|
||||||
'id' => Nickname::DISPLAY_FMT,
|
'id' => Nickname::INPUT_FMT,
|
||||||
'format' => '(xml|json|rss|atom)'));
|
'format' => '(xml|json|rss|atom)'));
|
||||||
|
|
||||||
$m->connect('api/favorites/create/:id.:format',
|
$m->connect('api/favorites/create/:id.:format',
|
||||||
array('action' => 'ApiFavoriteCreate',
|
array('action' => 'ApiFavoriteCreate',
|
||||||
'id' => Nickname::DISPLAY_FMT,
|
'id' => '[0-9]+',
|
||||||
'format' => '(xml|json)'));
|
'format' => '(xml|json)'));
|
||||||
|
|
||||||
$m->connect('api/favorites/destroy/:id.:format',
|
$m->connect('api/favorites/destroy/:id.:format',
|
||||||
array('action' => 'ApiFavoriteDestroy',
|
array('action' => 'ApiFavoriteDestroy',
|
||||||
'id' => Nickname::DISPLAY_FMT,
|
'id' => '[0-9]+',
|
||||||
'format' => '(xml|json)'));
|
'format' => '(xml|json)'));
|
||||||
// blocks
|
// blocks
|
||||||
|
|
||||||
@ -632,7 +632,7 @@ class Router
|
|||||||
|
|
||||||
$m->connect('api/blocks/create/:id.:format',
|
$m->connect('api/blocks/create/:id.:format',
|
||||||
array('action' => 'ApiBlockCreate',
|
array('action' => 'ApiBlockCreate',
|
||||||
'id' => Nickname::DISPLAY_FMT,
|
'id' => Nickname::INPUT_FMT,
|
||||||
'format' => '(xml|json)'));
|
'format' => '(xml|json)'));
|
||||||
|
|
||||||
$m->connect('api/blocks/destroy.:format',
|
$m->connect('api/blocks/destroy.:format',
|
||||||
@ -641,7 +641,7 @@ class Router
|
|||||||
|
|
||||||
$m->connect('api/blocks/destroy/:id.:format',
|
$m->connect('api/blocks/destroy/:id.:format',
|
||||||
array('action' => 'ApiBlockDestroy',
|
array('action' => 'ApiBlockDestroy',
|
||||||
'id' => Nickname::DISPLAY_FMT,
|
'id' => Nickname::INPUT_FMT,
|
||||||
'format' => '(xml|json)'));
|
'format' => '(xml|json)'));
|
||||||
// help
|
// help
|
||||||
|
|
||||||
@ -677,7 +677,7 @@ class Router
|
|||||||
|
|
||||||
$m->connect('api/statusnet/groups/timeline/:id.:format',
|
$m->connect('api/statusnet/groups/timeline/:id.:format',
|
||||||
array('action' => 'ApiTimelineGroup',
|
array('action' => 'ApiTimelineGroup',
|
||||||
'id' => Nickname::DISPLAY_FMT,
|
'id' => Nickname::INPUT_FMT,
|
||||||
'format' => '(xml|json|rss|atom)'));
|
'format' => '(xml|json|rss|atom)'));
|
||||||
|
|
||||||
$m->connect('api/statusnet/groups/show.:format',
|
$m->connect('api/statusnet/groups/show.:format',
|
||||||
@ -686,12 +686,12 @@ class Router
|
|||||||
|
|
||||||
$m->connect('api/statusnet/groups/show/:id.:format',
|
$m->connect('api/statusnet/groups/show/:id.:format',
|
||||||
array('action' => 'ApiGroupShow',
|
array('action' => 'ApiGroupShow',
|
||||||
'id' => Nickname::DISPLAY_FMT,
|
'id' => Nickname::INPUT_FMT,
|
||||||
'format' => '(xml|json)'));
|
'format' => '(xml|json)'));
|
||||||
|
|
||||||
$m->connect('api/statusnet/groups/join.:format',
|
$m->connect('api/statusnet/groups/join.:format',
|
||||||
array('action' => 'ApiGroupJoin',
|
array('action' => 'ApiGroupJoin',
|
||||||
'id' => Nickname::DISPLAY_FMT,
|
'id' => Nickname::INPUT_FMT,
|
||||||
'format' => '(xml|json)'));
|
'format' => '(xml|json)'));
|
||||||
|
|
||||||
$m->connect('api/statusnet/groups/join/:id.:format',
|
$m->connect('api/statusnet/groups/join/:id.:format',
|
||||||
@ -700,7 +700,7 @@ class Router
|
|||||||
|
|
||||||
$m->connect('api/statusnet/groups/leave.:format',
|
$m->connect('api/statusnet/groups/leave.:format',
|
||||||
array('action' => 'ApiGroupLeave',
|
array('action' => 'ApiGroupLeave',
|
||||||
'id' => Nickname::DISPLAY_FMT,
|
'id' => Nickname::INPUT_FMT,
|
||||||
'format' => '(xml|json)'));
|
'format' => '(xml|json)'));
|
||||||
|
|
||||||
$m->connect('api/statusnet/groups/leave/:id.:format',
|
$m->connect('api/statusnet/groups/leave/:id.:format',
|
||||||
@ -717,7 +717,7 @@ class Router
|
|||||||
|
|
||||||
$m->connect('api/statusnet/groups/list/:id.:format',
|
$m->connect('api/statusnet/groups/list/:id.:format',
|
||||||
array('action' => 'ApiGroupList',
|
array('action' => 'ApiGroupList',
|
||||||
'id' => Nickname::DISPLAY_FMT,
|
'id' => Nickname::INPUT_FMT,
|
||||||
'format' => '(xml|json|rss|atom)'));
|
'format' => '(xml|json|rss|atom)'));
|
||||||
|
|
||||||
$m->connect('api/statusnet/groups/list_all.:format',
|
$m->connect('api/statusnet/groups/list_all.:format',
|
||||||
@ -730,7 +730,7 @@ class Router
|
|||||||
|
|
||||||
$m->connect('api/statusnet/groups/membership/:id.:format',
|
$m->connect('api/statusnet/groups/membership/:id.:format',
|
||||||
array('action' => 'ApiGroupMembership',
|
array('action' => 'ApiGroupMembership',
|
||||||
'id' => Nickname::DISPLAY_FMT,
|
'id' => Nickname::INPUT_FMT,
|
||||||
'format' => '(xml|json)'));
|
'format' => '(xml|json)'));
|
||||||
|
|
||||||
$m->connect('api/statusnet/groups/create.:format',
|
$m->connect('api/statusnet/groups/create.:format',
|
||||||
@ -763,7 +763,7 @@ class Router
|
|||||||
|
|
||||||
$m->connect('api/statusnet/app/service/:id.xml',
|
$m->connect('api/statusnet/app/service/:id.xml',
|
||||||
array('action' => 'ApiAtomService',
|
array('action' => 'ApiAtomService',
|
||||||
'id' => Nickname::DISPLAY_FMT));
|
'id' => Nickname::INPUT_FMT));
|
||||||
|
|
||||||
$m->connect('api/statusnet/app/service.xml',
|
$m->connect('api/statusnet/app/service.xml',
|
||||||
array('action' => 'ApiAtomService'));
|
array('action' => 'ApiAtomService'));
|
||||||
|
Loading…
Reference in New Issue
Block a user