Skip to content
This repository has been archived by the owner on Aug 17, 2023. It is now read-only.

Commit

Permalink
#214 termに\xa0が含まれているケースへの対応
Browse files Browse the repository at this point in the history
  • Loading branch information
kemu3007 committed Nov 2, 2020
1 parent b9837ca commit 6058272
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 1 deletion.
2 changes: 1 addition & 1 deletion ChangeLog.rst
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ Unreleased
Release Notes - 2020-11-02
--------------------------
- [#213] リリースノートの最新バージョンの記述を返すversionコマンドを追加

- [#214] URLを含む語録が削除できないバグ修正

Release Notes - 2020-10-30
--------------------------
Expand Down
36 changes: 36 additions & 0 deletions src/alembic/migrations/versions/aa8a8e0293ac_replace_nbsp.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
"""replace &nbsp
Revision ID: aa8a8e0293ac
Revises: 98ecbc1e5b66
Create Date: 2020-11-02 12:48:17.045798
"""
import os

import sqlalchemy as sa
from sqlalchemy.orm import sessionmaker

from alembic import op
from haro.plugins.create_models import Term

# revision identifiers, used by Alembic.
revision = 'aa8a8e0293ac'
down_revision = '98ecbc1e5b66'
branch_labels = None
depends_on = None

engine = sa.create_engine(os.environ.get("SQLALCHEMY_URL"))
Session = sessionmaker(bind=engine)

def upgrade():
# ハイパーリンクがTerm.wordに含まれている場合、半角スペースが\xa0になってしまっているケースが存在するため置き換える
s = Session()
terms = s.query(Term).filter(Term.word.like('%\xa0%'))
print(terms)
for term in terms:
term.word = term.word.replace('\xa0', ' ')
s.commit()


def downgrade():
pass
4 changes: 4 additions & 0 deletions src/haro/plugins/create.py
Original file line number Diff line number Diff line change
Expand Up @@ -308,6 +308,8 @@ def del_term(message, command, word):
:param str command: 登録済のコマンド名
:param str word: 削除する語録
"""
# ハイパーリンクをコピペした際前後のスペースが\xa0になっているケースがあるため変換
word = word.replace('\xa0', ' ')
s = Session()
term = (s.query(Term)
.filter(Term.create_command == command.id)
Expand All @@ -330,6 +332,8 @@ def add_term(message, command, word):
:param str command: 登録済のコマンド名
:param str word: 登録する語録
"""
# ハイパーリンクをコピペした際前後のスペースが\xa0になっているケースがあるため変換
word = word.replace('\xa0', ' ')
s = Session()
term = (s.query(Term)
.select_from(join(Term, CreateCommand))
Expand Down

0 comments on commit 6058272

Please sign in to comment.