diff --git a/.github/scripts/git-get-shared-history.sh b/.github/scripts/git-get-shared-history.sh index 5c57f1e52e03..3b508fe315cb 100755 --- a/.github/scripts/git-get-shared-history.sh +++ b/.github/scripts/git-get-shared-history.sh @@ -20,6 +20,13 @@ set -euxo pipefail # We can always use some more history git -c protocol.version=2 fetch --deepen=100 + +# Find out if the PR is coming from a fork +base_clone_url=$(jq --raw-output '.pull_request.head.repo.clone_url' $GITHUB_EVENT_PATH) +# If it is, we need the fork's history, too. +if [[ $base_clone_url != "GoogleChrome/lighthouse.git" ]]; then + git -c protocol.version=2 fetch --deepen=100 "$base_clone_url" +fi echo "History is deepened." if git merge-base HEAD origin/master > /dev/null; then diff --git a/lighthouse-core/lib/page-functions.js b/lighthouse-core/lib/page-functions.js index 911938faa9dd..45b07c8d27a7 100644 --- a/lighthouse-core/lib/page-functions.js +++ b/lighthouse-core/lib/page-functions.js @@ -385,7 +385,9 @@ function getNodeLabel(node) { if (str.length <= maxLength) { return str; } - return str.slice(0, maxLength - 1) + 'โ€ฆ'; + // Take advantage of string iterator multi-byte character awareness. + // Regular `.slice` will ignore unicode character boundaries and lead to malformed text. + return Array.from(str).slice(0, maxLength - 1).join('') + 'โ€ฆ'; } const tagName = node.tagName.toLowerCase(); // html and body content is too broad to be useful, since they contain all page content diff --git a/lighthouse-core/test/lib/page-functions-test.js b/lighthouse-core/test/lib/page-functions-test.js index 90e8be1c2b25..41f512dec81e 100644 --- a/lighthouse-core/test/lib/page-functions-test.js +++ b/lighthouse-core/test/lib/page-functions-test.js @@ -116,6 +116,14 @@ describe('Page Functions', () => { assert.equal(pageFunctions.getNodeLabel(el).length, 80); }); + it('Truncates long text containing unicode surrogate pairs', () => { + const el = dom.createElement('div'); + // `getNodeLabel` truncates to 80 characters internally. + // We want to test a unicode character on the boundary. + el.innerText = Array(78).fill('a').join('') + '๐Ÿ’ก๐Ÿ’ก๐Ÿ’ก'; + assert.equal(pageFunctions.getNodeLabel(el), Array(78).fill('a').join('') + '๐Ÿ’กโ€ฆ'); + }); + it('Uses tag name for html tags', () => { const el = dom.createElement('html'); assert.equal(pageFunctions.getNodeLabel(el), 'html');