jenkins-bot has submitted this change and it was merged.
Change subject: Clone cached tables before returning them to users in
mw.wikibase
......................................................................
Clone cached tables before returning them to users in mw.wikibase
So that any changes they perform will not persist between several
invokes.
Bug: T76946
Change-Id: I6a085bec4190cbf158ef72125885b9d51e1c51a5
(cherry picked from commit 37c1ab3eb1938147e1f7f5a75bf29b1daf3732ac)
---
M client/includes/scribunto/mw.wikibase.lua
M client/tests/phpunit/includes/scribunto/LuaWikibaseLibraryTests.lua
2 files changed, 16 insertions(+), 5 deletions(-)
Approvals:
Aude: Looks good to me, approved
jenkins-bot: Verified
diff --git a/client/includes/scribunto/mw.wikibase.lua
b/client/includes/scribunto/mw.wikibase.lua
index a91b989..1ac0ff2 100644
--- a/client/includes/scribunto/mw.wikibase.lua
+++ b/client/includes/scribunto/mw.wikibase.lua
@@ -15,7 +15,7 @@
local php = mw_interface
mw_interface = nil
- -- Caching variable for the wikibase.entity objects
+ -- Caching variable for the entity tables as obtained from PHP
local entities = {}
-- Caching variable for the entity id string belonging to the current
page (nil if page is not linked to an entity)
local pageEntityId = false
@@ -30,11 +30,13 @@
return nil
end
- entities[ id ] = wikibase.entity.create( entity )
+ entities[ id ] = entity
end
if type( entities[ id ] ) == 'table' then
- return entities[ id ]
+ return wikibase.entity.create(
+ mw.clone( entities[ id ] ) -- Use a clone here,
so that people can't modify the entity
+ )
else
return nil
end
diff --git
a/client/tests/phpunit/includes/scribunto/LuaWikibaseLibraryTests.lua
b/client/tests/phpunit/includes/scribunto/LuaWikibaseLibraryTests.lua
index 5452d64..aafba0b 100644
--- a/client/tests/phpunit/includes/scribunto/LuaWikibaseLibraryTests.lua
+++ b/client/tests/phpunit/includes/scribunto/LuaWikibaseLibraryTests.lua
@@ -21,6 +21,13 @@
return type( mw.wikibase.getEntityObject() )
end
+local function testGetEntityObjectIsCloned()
+ mw.wikibase.getEntityObject( 'Q199024' ).id = 'a'
+
+ -- We should get a freshly cloned table here, so the changes above wont
persist
+ return mw.wikibase.getEntityObject( 'Q199024' ).id
+end
+
local function testGetEntityObjectSchemaVersion()
return mw.wikibase.getEntityObject().schemaVersion
end
@@ -40,6 +47,9 @@
},
{ name = 'mw.wikibase.getEntityObject (type)', func =
testGetEntityObjectType, type='ToString',
expect = { 'table' }
+ },
+ { name = 'mw.wikibase.getEntityObject (is cloned)', func =
testGetEntityObjectIsCloned, type='ToString',
+ expect = { 'Q199024' }
},
{ name = 'mw.wikibase.getEntityObject (schema version)', func =
testGetEntityObjectSchemaVersion,
expect = { 2 }
@@ -67,8 +77,7 @@
args = { 'Q32487' },
expect = { 'WikibaseClientLuaTest' }
},
- {
- name = 'mw.wikibase.sitelink', func = mw.wikibase.sitelink,
type='ToString',
+ { name = 'mw.wikibase.sitelink', func = mw.wikibase.sitelink,
type='ToString',
args = { 'Q32488' },
expect = { nil }
}
--
To view, visit https://gerrit.wikimedia.org/r/178273
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings
Gerrit-MessageType: merged
Gerrit-Change-Id: I6a085bec4190cbf158ef72125885b9d51e1c51a5
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/extensions/Wikibase
Gerrit-Branch: wmf/1.25wmf10
Gerrit-Owner: Aude <[email protected]>
Gerrit-Reviewer: Aude <[email protected]>
Gerrit-Reviewer: Hoo man <[email protected]>
Gerrit-Reviewer: Jackmcbarn <[email protected]>
Gerrit-Reviewer: jenkins-bot <>
_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits