c9s / Pux

Pux is a fast PHP Router and includes out-of-box controller tools

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

route '/' handling differs

kenjis opened this issue · comments

Sample code:

<?php
require __DIR__ . '/../vendor/autoload.php';
$mux = new Pux\Mux;
$mux->add('/', [ 'PageController', 'page1' ]);
$route = $mux->dispatch('/abc');
var_dump($route);

Result of 1.4.0:

NULL

Result of 1.5.0:

array(4) {
  [0] =>
  bool(false)
  [1] =>
  string(1) "/"
  [2] =>
  array(2) {
    [0] =>
    string(14) "PageController"
    [1] =>
    string(5) "page1"
  }
  [3] =>
  array(0) {
  }
}

Is this a bug or not?

I think it's a bug.. orz will fix that soon

OK, the prefix matching is used for Sub-mux dispatch. not sure the preferred behavior.

This behaviour is inherent from golang's net/http. however if we want to separate the comparing, we need to add one more condition for this.

Current implementation, all undefined URL match the '/' route. So we can't treat as 404. It is not good.

Agree

Fixed in 2ebcafb...90abdcf

The current behaviour is:

  1. when callback is a submux (integer), use prefix matching
  2. or use full-match.

Also added fallback tests