Các vấn đề thường gặpKý tự thoát chuỗi không mong đợi '&'
Ký tự thoát chuỗi không mong đợi '&'
Nếu bạn thấy thông báo lỗi này:
Unexpected string escaped character '&'...như ở đây:
{"message":"Unexpected string escaped character '&'","locations":[{"line":2596,"column":87}],"extensions":{"code":"gqlparser@4","specifiedBy":"https://spec.graphql.org/draft/#sec-Language"}}Giải pháp là: tắt và bật lại plugin.
Sau khi thực hiện, nếu bạn có plugin cache DB, bạn cũng phải xóa cache DB.
Giải thích vấn đề
Nguyên nhân của vấn đề là query GraphQL "translate-customposts" đã được lưu trữ không đúng trong cơ sở dữ liệu.
Có vẻ như điều này chỉ xảy ra lần đầu tiên plugin được cài đặt, và chỉ khi giấy phép đã được cung cấp trước, vì vậy lỗi này rất hiếm gặp.
Vì lý do nào đó (mà chúng tôi không hiểu rõ), WordPress có thể làm hỏng nội dung của query khi lưu trữ.
Mặc dù query gốc có nội dung như thế này:
@underJSONObjectProperty(
by: { key: "coreMediaTextAlt" }
affectDirectivesUnderPos: [1, 6]
)
@underJSONObjectProperty(
by: { key: "from" }
affectDirectivesUnderPos: [1, 4],
)
@underEachJSONObjectProperty
@underEachArrayItem(
passValueOnwardsAs: "value"
)
@applyField(
name: "_sprintf",
arguments: {
string: "#(<!-- wp:media-text .*?-->\\n?<div .*><figure .*><img .*?alt=\\\")%s(\\\")#",
values: [$value]
},
setResultInResponse: true
)
@export(
as: "coreMediaTextAltReplacementsFrom",
)
@underJSONObjectProperty(
by: { key: "to" }
)
@export(
as: "coreMediaTextAltReplacementsTo",
)...WordPress lưu nó trong DB như thế này:
@underJSONObjectProperty(
by: { key: "coreMediaTextAlt" }
affectDirectivesUnderPos: [1, 6]
)
@underJSONObjectProperty(
by: { key: "from" }
affectDirectivesUnderPos: [1, 4],
)
@underEachJSONObjectProperty
@underEachArrayItem(
passValueOnwardsAs: "value"
)
@applyField(
name: "_sprintf",
arguments: {
string: "#(<!-- wp:media-text .*?-->\\n?<div><figure><img .*?alt=\\\")%s(\\\")#",
values: [$value]
},
setResultInResponse: true
)
@export(
as: "coreMediaTextAltReplacementsFrom",
)
@underJSONObjectProperty(
by: { key: "to" }
)
@export(
as: "coreMediaTextAltReplacementsTo",
)Khi tắt và bật lại plugin, query sẽ được lưu lại vào cơ sở dữ liệu và vấn đề được khắc phục.