From 1b9bd70bb15b6535bd44c6e4fbeafcd676036c36 Mon Sep 17 00:00:00 2001 From: Henrik Giesel Date: Sun, 9 Aug 2020 10:35:52 +0200 Subject: [PATCH 1/8] Move remove null bytes functionality to editor_will_munge_html hook --- qt/aqt/editor.py | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/qt/aqt/editor.py b/qt/aqt/editor.py index 083f0fd9d..d9ba3a11a 100644 --- a/qt/aqt/editor.py +++ b/qt/aqt/editor.py @@ -389,8 +389,6 @@ class Editor: print("ignored late blur") return txt = self.mungeHTML(txt) - # misbehaving apps may include a null byte in the text - txt = txt.replace("\x00", "") # reverse the url quoting we added to get images to display txt = self.mw.col.media.escapeImages(txt, unescape=True) self.note.fields[ord] = txt @@ -1202,6 +1200,10 @@ def fontMungeHack(font): def munge_html(txt, editor): return "" if txt in ("
", "

") else txt +def remove_null_bytes(txt, editor): + # misbehaving apps may include a null byte in the text + return txt.replace("\x00", "") gui_hooks.editor_will_use_font_for_field.append(fontMungeHack) gui_hooks.editor_will_munge_html.append(munge_html) +gui_hooks.editor_will_munge_html.append(remove_null_bytes) From f5479edaccecfe99d35b4062040279518a57953d Mon Sep 17 00:00:00 2001 From: Henrik Giesel Date: Sun, 9 Aug 2020 10:37:38 +0200 Subject: [PATCH 2/8] Move reverse url quoting functionality to editor_will_munge_html hook --- qt/aqt/editor.py | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/qt/aqt/editor.py b/qt/aqt/editor.py index d9ba3a11a..e31958bba 100644 --- a/qt/aqt/editor.py +++ b/qt/aqt/editor.py @@ -389,8 +389,6 @@ class Editor: print("ignored late blur") return txt = self.mungeHTML(txt) - # reverse the url quoting we added to get images to display - txt = self.mw.col.media.escapeImages(txt, unescape=True) self.note.fields[ord] = txt if not self.addMode: self.note.flush() @@ -1204,6 +1202,11 @@ def remove_null_bytes(txt, editor): # misbehaving apps may include a null byte in the text return txt.replace("\x00", "") +def reverse_url_quoting(txt, editor): + # reverse the url quoting we added to get images to display + return editor.mw.col.media.escapeImages(txt, unescape=True) + gui_hooks.editor_will_use_font_for_field.append(fontMungeHack) gui_hooks.editor_will_munge_html.append(munge_html) gui_hooks.editor_will_munge_html.append(remove_null_bytes) +gui_hooks.editor_will_munge_html.append(reverse_url_quoting) From ee3d4f5ad887f4eb4ec8092dded3e8ca34938c00 Mon Sep 17 00:00:00 2001 From: Henrik Giesel Date: Sun, 9 Aug 2020 10:38:31 +0200 Subject: [PATCH 3/8] Avoid extra assignment --- qt/aqt/editor.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/qt/aqt/editor.py b/qt/aqt/editor.py index e31958bba..8b4bdc28b 100644 --- a/qt/aqt/editor.py +++ b/qt/aqt/editor.py @@ -388,8 +388,9 @@ class Editor: if nid != self.note.id: print("ignored late blur") return - txt = self.mungeHTML(txt) - self.note.fields[ord] = txt + + self.note.fields[ord] = self.mungeHTML(txt) + if not self.addMode: self.note.flush() self.mw.requireReset() From 17f23221e427007aee97e024dfd69eb6d9cc7459 Mon Sep 17 00:00:00 2001 From: Henrik Giesel Date: Sun, 9 Aug 2020 11:16:19 +0200 Subject: [PATCH 4/8] Add newlines --- qt/aqt/editor.py | 3 +++ 1 file changed, 3 insertions(+) diff --git a/qt/aqt/editor.py b/qt/aqt/editor.py index 8b4bdc28b..4b79d7897 100644 --- a/qt/aqt/editor.py +++ b/qt/aqt/editor.py @@ -1199,14 +1199,17 @@ def fontMungeHack(font): def munge_html(txt, editor): return "" if txt in ("
", "

") else txt + def remove_null_bytes(txt, editor): # misbehaving apps may include a null byte in the text return txt.replace("\x00", "") + def reverse_url_quoting(txt, editor): # reverse the url quoting we added to get images to display return editor.mw.col.media.escapeImages(txt, unescape=True) + gui_hooks.editor_will_use_font_for_field.append(fontMungeHack) gui_hooks.editor_will_munge_html.append(munge_html) gui_hooks.editor_will_munge_html.append(remove_null_bytes) From 1e5250cd0d35f9e1d36c9b03dbd3e13f8de20cfd Mon Sep 17 00:00:00 2001 From: Henrik Giesel Date: Sun, 9 Aug 2020 16:38:27 +0200 Subject: [PATCH 5/8] Reset cargo index cache by bumping its number from 22 to 23 --- .github/workflows/checks.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/checks.yml b/.github/workflows/checks.yml index 02a26e4cb..f51b624c8 100644 --- a/.github/workflows/checks.yml +++ b/.github/workflows/checks.yml @@ -197,7 +197,7 @@ jobs: uses: actions/cache@v1 with: path: ${{ matrix.CARGO_INDEX_DIR }} - key: ${{ runner.os }}-cargo-index-${{ hashFiles('**/requirements.*') }}-${{ hashFiles('**/setup.py') }}-${{ hashFiles('**/Makefile') }}-${{ hashFiles('**/Cargo.toml') }}-22- + key: ${{ runner.os }}-cargo-index-${{ hashFiles('**/requirements.*') }}-${{ hashFiles('**/setup.py') }}-${{ hashFiles('**/Makefile') }}-${{ hashFiles('**/Cargo.toml') }}-23- - name: Cache cargo registry if: matrix.python == '3.7' From 79c2e3139182822dc0dd3637b724164b99ea006b Mon Sep 17 00:00:00 2001 From: Henrik Giesel Date: Sun, 9 Aug 2020 17:01:22 +0200 Subject: [PATCH 6/8] Reset the cargo registry --- .github/workflows/checks.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/checks.yml b/.github/workflows/checks.yml index f51b624c8..5d91ddbbb 100644 --- a/.github/workflows/checks.yml +++ b/.github/workflows/checks.yml @@ -204,7 +204,7 @@ jobs: uses: actions/cache@v1 with: path: ${{ matrix.CARGO_REGISTRY_DIR }} - key: ${{ runner.os }}-cargo-registry-${{ hashFiles('**/requirements.*') }}-${{ hashFiles('**/setup.py') }}-${{ hashFiles('**/Makefile') }}-${{ hashFiles('**/Cargo.toml') }}-22- + key: ${{ runner.os }}-cargo-registry-${{ hashFiles('**/requirements.*') }}-${{ hashFiles('**/setup.py') }}-${{ hashFiles('**/Makefile') }}-${{ hashFiles('**/Cargo.toml') }}-23- - name: Cache cargo target if: matrix.python == '3.7' From c4522ff56de2ad2adb76295c74eee8dc30a44560 Mon Sep 17 00:00:00 2001 From: Henrik Giesel Date: Sun, 9 Aug 2020 17:05:29 +0200 Subject: [PATCH 7/8] Reset the cargo rslib --- .github/workflows/checks.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/checks.yml b/.github/workflows/checks.yml index 5d91ddbbb..3b41be24d 100644 --- a/.github/workflows/checks.yml +++ b/.github/workflows/checks.yml @@ -218,7 +218,7 @@ jobs: uses: actions/cache@v1 with: path: ${{ github.workspace }}${{ matrix.SEP }}rslib${{ matrix.SEP }}target - key: ${{ runner.os }}-cargo-rslib-${{ hashFiles('**/requirements.*') }}-${{ hashFiles('**/setup.py') }}-${{ hashFiles('**/Makefile') }}-${{ hashFiles('**/Cargo.toml') }}-${{ matrix.BUILD_TYPE }}-22- + key: ${{ runner.os }}-cargo-rslib-${{ hashFiles('**/requirements.*') }}-${{ hashFiles('**/setup.py') }}-${{ hashFiles('**/Makefile') }}-${{ hashFiles('**/Cargo.toml') }}-${{ matrix.BUILD_TYPE }}-23- - name: Cache cargo rspy if: matrix.python == '3.7' From ce85169f13f5fd6ff3ca5b4e598e5c5c903ec6df Mon Sep 17 00:00:00 2001 From: Henrik Giesel Date: Sun, 9 Aug 2020 17:18:05 +0200 Subject: [PATCH 8/8] Reset cargo rspy --- .github/workflows/checks.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/checks.yml b/.github/workflows/checks.yml index 3b41be24d..612b0c336 100644 --- a/.github/workflows/checks.yml +++ b/.github/workflows/checks.yml @@ -225,7 +225,7 @@ jobs: uses: actions/cache@v1 with: path: ${{ github.workspace }}${{ matrix.SEP }}rspy${{ matrix.SEP }}target - key: ${{ runner.os }}-cargo-rspy-${{ hashFiles('**/requirements.*') }}-${{ hashFiles('**/setup.py') }}-${{ hashFiles('**/Makefile') }}-${{ hashFiles('**/Cargo.toml') }}-${{ matrix.BUILD_TYPE }}-22- + key: ${{ runner.os }}-cargo-rspy-${{ hashFiles('**/requirements.*') }}-${{ hashFiles('**/setup.py') }}-${{ hashFiles('**/Makefile') }}-${{ hashFiles('**/Cargo.toml') }}-${{ matrix.BUILD_TYPE }}-23- - name: Set up curl pyaudio, rsync if: matrix.os == 'windows-latest'