8000 fix: only check for special characters in fieldname (backport #19061) (backport #19067) by mergify[bot] · Pull Request #19069 · frappe/frappe · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

fix: only check for special characters in fieldname (backport #19061) (backport #19067) #19069

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Dec 1, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 4 additions & 6 deletions frappe/core/doctype/file/file.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@

import frappe
from frappe import _, conf, safe_decode
from frappe.database.schema import SPECIAL_CHAR_PATTERN
from frappe.model.document import Document
from frappe.utils import (
call_hook_method,
Expand Down Expand Up @@ -145,13 +146,10 @@ def validate_attachment_references(self):
if not self.attached_to_doctype:
return

if self.attached_to_name and not isinstance(self.attached_to_name, str):
frappe.throw(_("Attached To Name must be a string"), TypeError)
if not self.attached_to_name or not isinstance(self.attached_to_name, (str, int)):
frappe.throw(_("Attached To Name must be a string or an integer"), frappe.ValidationError)

if not self.attached_to_field:
return

if not frappe.get_meta(self.attached_to_doctype).has_field(self.attached_to_field):
if self.attached_to_field and SPECIAL_CHAR_PATTERN.search(self.attached_to_field):
frappe.throw(_("The fieldname you've specified in Attached To Field is invalid"))

def validate_url(self):
Expand Down
2 changes: 1 addition & 1 deletion frappe/core/doctype/file/test_file.py
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ def setUp(self):
"doctype": "File",
"file_name": "test_base64.txt",
"attached_to_doctype": self.attached_to_doctype,
"attached_to_docname": self.attached_to_docname,
"attached_to_name": self.attached_to_docname,
"content": self.test_content,
"decode": True,
}
Expand Down
4 changes: 3 additions & 1 deletion frappe/database/schema.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@
from frappe import _
from frappe.utils import cint, cstr, flt

SPECIAL_CHAR_PATTERN = re.compile(r"[\W]", flags=re.UNICODE)


class InvalidColumnName(frappe.ValidationError):
pass
Expand Down Expand Up @@ -299,7 +301,7 @@ def default_changed_for_decimal(self, current_def):


def validate_column_name(n):
special_characters = re.findall(r"[\W]", n, re.UNICODE)
special_characters = SPECIAL_CHAR_PATTERN.findall(n)
if special_characters:
special_characters = ", ".join('"{0}"'.format(c) for c in special_characters)
frappe.throw(
Expand Down
2 changes: 1 addition & 1 deletion frappe/public/js/frappe/form/controls/attach.js
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ frappe.ui.form.ControlAttach = frappe.ui.form.ControlData.extend({
if (this.frm) {
options.doctype = this.frm.doctype;
options.docname = this.frm.docname;
options.fieldname = this.grid ? this.grid.df.fieldname : this.df.fieldname;
options.fieldname = this.df.fieldname;
options.make_attachments_public = this.frm.meta.make_attachments_public;
}

Expand Down
0