{"action":"created","issue":{"url":"https://api.github.com/repos/ezsystems/LegacyBridge/issues/62","repository_url":"https://api.github.com/repos/ezsystems/LegacyBridge","labels_url":"https://api.github.com/repos/ezsystems/LegacyBridge/issues/62/labels{/name}","comments_url":"https://api.github.com/repos/ezsystems/LegacyBridge/issues/62/comments","events_url":"https://api.github.com/repos/ezsystems/LegacyBridge/issues/62/events","html_url":"https://github.com/ezsystems/LegacyBridge/pull/62","id":174001445,"number":62,"title":"Fix EZP-26181: Content with same name as URL matcher will lead to broken links","user":{"login":"glye","id":289744,"avatar_url":"https://avatars.githubusercontent.com/u/289744?v=3","gravatar_id":"","url":"https://api.github.com/users/glye","html_url":"https://github.com/glye","followers_url":"https://api.github.com/users/glye/followers","following_url":"https://api.github.com/users/glye/following{/other_user}","gists_url":"https://api.github.com/users/glye/gists{/gist_id}","starred_url":"https://api.github.com/users/glye/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/glye/subscriptions","organizations_url":"https://api.github.com/users/glye/orgs","repos_url":"https://api.github.com/users/glye/repos","events_url":"https://api.github.com/users/glye/events{/privacy}","received_events_url":"https://api.github.com/users/glye/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":17,"created_at":"2016-08-30T12:04:36Z","updated_at":"2016-09-21T09:18:01Z","closed_at":null,"pull_request":{"url":"https://api.github.com/repos/ezsystems/LegacyBridge/pulls/62","html_url":"https://github.com/ezsystems/LegacyBridge/pull/62","diff_url":"https://github.com/ezsystems/LegacyBridge/pull/62.diff","patch_url":"https://github.com/ezsystems/LegacyBridge/pull/62.patch"},"body":"> Fixes https://jira.ez.no/browse/EZP-26181\r\n> Status: Ready for review\r\n\r\n(PR against master since there are no versioned branches here.)\r\n\r\nThis is caused by the use of `array_diff` to determine the siteaccess part of the URL, here:\r\nhttps://github.com/ezsystems/LegacyBridge/blob/master/bundle/LegacyMapper/SiteAccess.php#L88\r\nWhen the the path-without-siteaccess contains an element that equals the siteaccess, the diff is empty, and the siteaccess is not found, and subsequently removed from all URLs.\r\n\r\nExample: The siteaccess is `Admin` and we're requesting `/Media/Images/Admin/EZP-26181`. Before this PR, this means that:\r\n`$pathinfo = /Admin/Media/Images/Admin/EZP-26181`\r\n`$semanticPathinfo = /Media/Images/Admin/EZP-26181`\r\nThe paths are broken into path element arrays, and diffed:\r\n```\r\narray_diff(\r\n    [Admin, Media, Images, Admin, EZP-26181],\r\n    [Media, Images, Admin, EZP-26181]\r\n)\r\n```\r\nThe result of this is an empty array, as all elements of the second parameter exist in the first - array_diff() doesn't care that \"Admin\" is in there twice. So the `$uriPart` is empty, meaning the siteaccess was not found.\r\n\r\nThe fix is to start at the end/right of the paths, and chop off the bit that is equal. What's left, literally and figuratively, is the siteaccess uri part.\r\n\r\nExample: After the PR, we have the same input strings:\r\n`$pathinfo = /Admin/Media/Images/Admin/EZP-26181`\r\n`$semanticPathinfo = /Media/Images/Admin/EZP-26181`\r\nNow we lookup the position of `$semanticPathinfo` within `$pathinfo` directly using mb_strrpos (i.e. backwards). The `$uriPart` is taken to be whatever is to the left of that, i.e. `/Admin`.\r\n\r\nNB: This fixes the bug according to steps-to-reproduce, but I'm not sure I'm dealing with fragment path items the right way.\r\n\r\n- [x] Add test\r\n- [x] Deal with the posibility of mb_strrpos() returning false? i.e. semantic pathinfo not found within pathinfo, which Should Not Happen(TM)"},"comment":{"url":"https://api.github.com/repos/ezsystems/LegacyBridge/issues/comments/248556575","html_url":"https://github.com/ezsystems/LegacyBridge/pull/62#issuecomment-248556575","issue_url":"https://api.github.com/repos/ezsystems/LegacyBridge/issues/62","id":248556575,"user":{"login":"glye","id":289744,"avatar_url":"https://avatars.githubusercontent.com/u/289744?v=3","gravatar_id":"","url":"https://api.github.com/users/glye","html_url":"https://github.com/glye","followers_url":"https://api.github.com/users/glye/followers","following_url":"https://api.github.com/users/glye/following{/other_user}","gists_url":"https://api.github.com/users/glye/gists{/gist_id}","starred_url":"https://api.github.com/users/glye/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/glye/subscriptions","organizations_url":"https://api.github.com/users/glye/orgs","repos_url":"https://api.github.com/users/glye/repos","events_url":"https://api.github.com/users/glye/events{/privacy}","received_events_url":"https://api.github.com/users/glye/received_events","type":"User","site_admin":false},"created_at":"2016-09-21T09:18:01Z","updated_at":"2016-09-21T09:18:01Z","body":"I just realised I should have opened this against ezpublish-kernel-ee 5.3/5.4 and forward ported to LegacyBridge. Since it's approved I'll just push it there, and port from there."}}
{"actor":{"display_login":"glye"}}