Making WordPress.org

Changeset 10475


Ignore:
Timestamp:
11/30/2020 05:40:43 AM (6 years ago)
Author:
dd32
Message:

Events API: Don't strip commas when performing location lookups. This allows for disambiguation to occur better by treating commas as separators.

See #3367.

Location:
sites/trunk/api.wordpress.org/public_html/events/1.0
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • sites/trunk/api.wordpress.org/public_html/events/1.0/index.php

    r10474 r10475  
    135135        // Simplified parameters for lookup by location (city) name, with optional timezone and locale params for extra context.
    136136        if ( isset( $_REQUEST['location'] ) ) {
    137                 $location_args['location_name'] = trim( str_replace( ',', ' ', $_REQUEST['location'] ) );
     137                $location_args['location_name'] = trim( $_REQUEST['location'] );
    138138        }
    139139
     
    311311         * delimiter.
    312312         */
    313         $location_name_parts = preg_split( '/\s+/u', $location_name );
     313        $location_name_parts = preg_split( '/[,\s]+/u', $location_name );
    314314        $location_word_count = count( $location_name_parts );
    315315
  • sites/trunk/api.wordpress.org/public_html/events/1.0/tests/test-index.php

    r10474 r10475  
    619619                                'longitude'   => '-74.082',
    620620                                'country'     => 'CO',
     621                        ),
     622                ),
     623
     624                // https://meta.trac.wordpress.org/ticket/3367
     625                // The following tests ensure that West/East portlands return correctly with inversed timezones.
     626                'usa-city-disambiguation' => array(
     627                        'input' => array(
     628                                'location_name' => 'Portland',
     629                                'locale'        => 'en_US',
     630                                'timezone'      => 'America/Los_Angeles',
     631                        ),
     632                        'expected' => array(
     633                                'description' => 'portland',
     634                                'latitude'    => '45.523',
     635                                'longitude'   => '-122.676',
     636                                'country'     => 'US',
     637                        ),
     638                ),
     639                'usa-city-disambiguation-2' => array(
     640                        'input' => array(
     641                                'location_name' => 'Portland, OR',
     642                                'locale'        => 'en_US',
     643                                'timezone'      => 'America/New_York',
     644                        ),
     645                        'expected' => array(
     646                                'description' => 'portland, or',
     647                                'latitude'    => '45.523',
     648                                'longitude'   => '-122.676',
     649                                'country'     => 'US',
     650                        ),
     651                ),
     652                'usa-city-disambiguation-3' => array(
     653                        'input' => array(
     654                                'location_name' => 'Portland',
     655                                'locale'        => 'en_US',
     656                                'timezone'      => 'America/New_York',
     657                        ),
     658                        'expected' => array(
     659                                'description' => 'portland',
     660                                'latitude'    => '43.657',
     661                                'longitude'   => '-70.259',
     662                                'country'     => 'US',
     663                        ),
     664                ),
     665                'usa-city-disambiguation-4' => array(
     666                        'input' => array(
     667                                'location_name' => 'Portland, ME',
     668                                'locale'        => 'en_US',
     669                                'timezone'      => 'America/Los_Angeles',
     670                        ),
     671                        'expected' => array(
     672                                'description' => 'portland, me',
     673                                'latitude'    => '43.657',
     674                                'longitude'   => '-70.259',
     675                                'country'     => 'US',
    621676                        ),
    622677                ),
Note: See TracChangeset for help on using the changeset viewer.