Coverage for  / home / runner / work / viur-core / viur-core / viur / src / viur / core / bones / raw.py: 28%

17 statements  

« prev     ^ index     » next       coverage.py v7.12.0, created at 2025-11-24 12:24 +0000

1import re 

2from viur.core.bones.base import BaseBone, ReadFromClientError, ReadFromClientErrorSeverity 

3 

4SEARCH_TAGS = re.compile(r"[^\s]+") 

5 

6 

7class RawBone(BaseBone): 

8 """ 

9 Stores its data without applying any pre/post-processing or filtering. 

10 Can be used to store any textual content. 

11 

12 Use the dot-notation like "raw.code.markdown" or similar to describe subsequent types. 

13 This can also be achieved by adding `type_suffix="code.markdown"` to the RawBone's instantiation. 

14 

15 ..Warning: Using this bone will lead to security vulnerabilities like reflected XSS unless the 

16 data is either otherwise validated/stripped or from a trusted source! Don't use this unless 

17 you fully understand it's implications! 

18 """ 

19 type = "raw" 

20 

21 def singleValueFromClient(self, value, skel, bone_name, client_data): 

22 if err := self.isInvalid(value): 

23 return value, [ReadFromClientError(ReadFromClientErrorSeverity.Invalid, err)] 

24 

25 return value, None 

26 

27 def getSearchTags(self, skel: "SkeletonInstance", name: str) -> set[str]: 

28 result = set() 

29 

30 for idx, lang, value in self.iter_bone_value(skel, name): 

31 if not value: 

32 continue 

33 

34 for tag in re.finditer(SEARCH_TAGS, str(value)): 

35 result.add(tag.group()) 

36 

37 return result